File: 10_prototypes.t

package info (click to toggle)
libsub-wrappackages-perl 2.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 664; sh: 3; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 583 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl -w

use strict;

my $pre;
my $post;

use Test::More tests => 4;

sub mypush(\@@) { @{$_[0]} = (@{$_[0]}, @_[1..$#_]); }

BEGIN {
  my @array = ();
  mypush @array, (1,2);
  is_deeply(\@array, [1, 2], "without wrapping, prototyped function works");
  ok(!$pre, "... and yes, it really wasn't wrapped");
}

use Sub::WrapPackages (
  subs => [qw(main::mypush)],
  pre => sub { $pre  = 'pre' }
);

my @array = ();
mypush @array, (1,2);
is_deeply(\@array, [1, 2], "with wrapping, prototyped function still works");
ok($pre eq 'pre', "... and yes, it really was wrapped");