]> git.vpit.fr Git - perl/modules/Sub-Op.git/blob - samples/try.pl
Rename Sub::Op::Test to Sub::Op::LexicalSub
[perl/modules/Sub-Op.git] / samples / try.pl
1 #!perl
2
3 use 5.010;
4
5 use strict;
6 use warnings;
7
8 use blib;
9 use blib 't/Sub-Op-LexicalSub';
10
11 my $code = $ARGV[0];
12 die "Usage: $0 'code involving f() and g()'" unless defined $code;
13
14 my $cb = eval <<"CODE";
15  use Sub::Op::LexicalSub f => sub { say 'f(' . join(', ', \@_) . ')'; \@_ };
16  use Sub::Op::LexicalSub g => sub { say 'g(' . join(', ', \@_) . ')'; \@_ };
17  sub { $code }
18 CODE
19 die $@ if $@;
20
21 print "--- run ---\n";
22 eval { $cb->() };
23 warn "exception: $@" if $@;
24
25 print "--- deparse ---\n";
26 use B::Deparse;
27 print B::Deparse->new->coderef2text($cb), "\n";
28
29 print "--- concise ---\n";
30 use B::Concise;
31 B::Concise::compile($cb)->();
32
33 print "--- concise(exec) ---\n";
34 B::Concise::compile('-exec', $cb)->();