]> git.vpit.fr Git - perl/modules/Sub-Prototype-Util.git/blob - samples/try.pl
57477fe9c493c711b1885233e13cacb9bca0d89f
[perl/modules/Sub-Prototype-Util.git] / samples / try.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use Data::Dumper;
7
8 use lib qw{blib/lib};
9
10 use Sub::Prototype::Util qw/flatten recall wrap/;
11
12 my @a = qw/a b c/;
13 print "At the beginning, \@a contains :\n", Dumper(\@a);
14
15 my @args = ( \@a, 1, { d => 2 }, undef, 3 );
16 print "Our arguments are :\n", Dumper(\@args);
17
18 my $proto = '\@$;$';
19 my @flat = flatten $proto, @args; # ('a', 'b', 'c', 1, { d => 2 })
20 print "When flatten with prototype $proto, this gives :\n", Dumper(\@flat);
21
22 recall 'CORE::push', @args; # @a contains 'a', 'b', 'c', 1, { d => 2 }, undef, 3
23 print "After recalling CORE::push with \@args, \@a contains :\n", Dumper(\@a);
24
25 my $splice = wrap 'CORE::splice';
26 my @b = $splice->(\@a, 4, 2);
27 print "After calling wrapped splice with \@a, it contains :\n", Dumper(\@a);
28 print "What was returned :\n", Dumper(\@b);