From: Vincent Pit Date: Thu, 28 Aug 2008 17:53:38 +0000 (+0200) Subject: Add the sample/subs.pl script X-Git-Tag: v0.03~5 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fsubs-auto.git;a=commitdiff_plain;h=63f28765be6e99c35367e4c048ec89ab1d5d5138 Add the sample/subs.pl script --- diff --git a/MANIFEST b/MANIFEST index 98795b0..b9a3291 100644 --- 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 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'; +}