]> git.vpit.fr Git - perl/modules/subs-auto.git/commitdiff
Add the sample/subs.pl script
authorVincent Pit <vince@profvince.com>
Thu, 28 Aug 2008 17:53:38 +0000 (19:53 +0200)
committerVincent Pit <vince@profvince.com>
Thu, 28 Aug 2008 17:53:38 +0000 (19:53 +0200)
MANIFEST
samples/subs.pl [new file with mode: 0644]

index 98795b04c1de31db54c6e3922927c32f9a2110c6..b9a3291b87a13ff3e0dcdaa1fded3bc26b083d96 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3,6 +3,7 @@ MANIFEST
 Makefile.PL
 README
 lib/subs/auto.pm
+samples/subs.pl
 t/00-load.t
 t/05-args.t
 t/10-base.t
diff --git a/samples/subs.pl b/samples/subs.pl
new file mode 100644 (file)
index 0000000..8d25208
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use lib qw{blib/lib};
+
+my $x = 7;
+my @a = qw/ba na na/;
+
+{
+ use subs::auto;
+ foo;             # Compile to "foo()"     instead of croaking
+ foo $x;          # Compile to "foo($x)"   instead of "$x->foo"
+ foo 1;           # Compile to "foo(1)"    instead of croaking
+ foo 1, 2;        # Compile to "foo(1, 2)" instead of croaking
+ foo(@a);         # Still ok
+ foo->import;     # Compile to "foo()->import()"
+ select STDERR;
+ print foo 'wut'; # Compile to "print(foo('wut'))"
+}
+
+print "\n";
+
+eval "bar"; # not defined, BOOM
+warn 'died: ' . $@ if $@;
+
+sub foo {
+ my $s = @_ ? join ',', @_ : '(nothing)';
+ warn "foo got $s\n";
+ 'strict';
+}