blib/lib/Sub/Prepend.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 100% 52 / 52 CC 2 SCAR 1.7
CC
2
Cov
100%
prepend
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 package Sub::Prepend;
2 6 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 6 $VERSION = 0.01;
5  
6 6 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 @ISA = Exporter::;
8 6 @EXPORT_OK = qw/ prepend /;
9 6 $EXPORT_TAGS{ALL} = \@EXPORT_OK;
10  
11 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Scalar::Util 1.11 'set_prototype';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Symbol qw/ qualify_to_ref qualify /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use vars qw/ $CALLER /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 *CALLER = \1;
19  
20 8 ▶sub prepend {
Subroutine prepend: called CC=2 SCAR=6.9
Pod documented
21 8 my ($name, $code) = @_;
22  
23 8 my $glob = qualify_to_ref($name => scalar caller);
24  
25 8 ▶ defined &$glob
Branch: 1 branch
BranchTrueFalseTotal
defined &$glob or croak(sprintf("Sub::Prepend: Subroutine &%s not defined", &qualify($name, scalar caller))) 7 1 8
26 or croak(sprintf __PACKAGE__ . ": Subroutine &%s not defined", qualify($name => scalar caller));
27  
28 7 my $orig = \&$glob;
29  
30 my $prepender = set_prototype(
31 7 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 7 &$code; # Don't use parenthesis!
33 7 goto &$orig;
34 },
35 7 prototype $orig
36 );
37  
38 {
39 6 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 7 *$glob = $prepender;
41 }
42  
43 7 return;
44 }
45  
46 6 1;
47  
48 __END__
↑ Summary