X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Fsubs.pl;fp=samples%2Fsubs.pl;h=8d25208fc1290015c9858a85e682429a163e7273;hb=63f28765be6e99c35367e4c048ec89ab1d5d5138;hp=0000000000000000000000000000000000000000;hpb=49879973c101332e3eedf8e2abb66bae5d3eaac5;p=perl%2Fmodules%2Fsubs-auto.git diff --git a/samples/subs.pl b/samples/subs.pl new file mode 100644 index 0000000..8d25208 --- /dev/null +++ b/samples/subs.pl @@ -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'; +}