]> git.vpit.fr Git - perl/modules/subs-auto.git/blob - samples/subs.pl
Add the sample/subs.pl script
[perl/modules/subs-auto.git] / samples / subs.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use lib qw{blib/lib};
7
8 my $x = 7;
9 my @a = qw/ba na na/;
10
11 {
12  use subs::auto;
13  foo;             # Compile to "foo()"     instead of croaking
14  foo $x;          # Compile to "foo($x)"   instead of "$x->foo"
15  foo 1;           # Compile to "foo(1)"    instead of croaking
16  foo 1, 2;        # Compile to "foo(1, 2)" instead of croaking
17  foo(@a);         # Still ok
18  foo->import;     # Compile to "foo()->import()"
19  select STDERR;
20  print foo 'wut'; # Compile to "print(foo('wut'))"
21 }
22
23 print "\n";
24
25 eval "bar"; # not defined, BOOM
26 warn 'died: ' . $@ if $@;
27
28 sub foo {
29  my $s = @_ ? join ',', @_ : '(nothing)';
30  warn "foo got $s\n";
31  'strict';
32 }