blib/lib/Class/MakeMethods/Emulator.pm

filter: Statementstmt 74.1% 46 / 62 Branchbran 62.5% 10 / 16 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 68.3% 67 / 98 CC 12 SCAR 15.0
CC
12
Cov
71%
_handle_namespace
6.6
import
5.1
namespace_release
4.4
CRAP 4.5
« blib/lib/Class/MakeMethods/Attribute.pm ↑ Summary blib/lib/Class/MakeMethods/Template/Universal.pm »
1 package Class::MakeMethods::Emulator;
2  
3 21 $VERSION = 1.009;
4  
5 ########################################################################
6 ### IMPORT BEHAVIOR: import(), _handle_namespace()
7 ########################################################################
8  
9 21 @EXPORT_OK = qw( namespace_capture namespace_release );
10 10 ▶sub import {
Subroutine import: called CC=5 SCAR=16.3
11
12 10 ▶ if ( scalar @_ == 2 and $_[1] eq '-isasubclass' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2 and $_[1] eq "-isasubclass") 8 2 10
Condition66%2/3
scalar @_ == 2 and $_[1] eq "-isasubclass"
!ll&&!rl&&r
208
MC/DC50%1/2
scalar @_ == 2 and $_[1] eq "-isasubclass"
scalar @_ == 2 $_[1] eq "-isasubclass"
Truth table66%2/3
A and B
A= scalar @_ == 2B= $_[1] eq "-isasubclass"
ABresult
0X0
100
111
13 8 splice @_, 1, 1;
14 8 my $target_class = ( caller )[0];
15 21 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 push @{"$target_class\::ISA"}, $_[0];
17 }
18
19 10 ▶ if ( $_[0] eq __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] eq __PACKAGE__) 10 0 10
20 10 ▶ require Exporter and goto &Exporter::import # lazy Exporter
Branch: 1 branch
BranchTrueFalseTotal
require Exporter and goto \&Exporter::import 10 0 10
21 }
22 }
23  
24 23 ▶sub _handle_namespace {
Subroutine _handle_namespace: called CC=6 SCAR=18.8
25 23 my $class = shift;
26 23 my $emulation_target = shift;
27 23 ▶ my $firstarg = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $firstarg = shift() or return 18 5 23
28 18 ▶ my $take = shift || '-take_namespace';
Condition50%1/2
shift() || '-take_namespace'
l!l
018
MC/DC0%0/1
shift() || '-take_namespace'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
29 18 ▶ my $release = shift || '-release_namespace';
Condition50%1/2
shift() || '-release_namespace'
l!l
018
MC/DC0%0/1
shift() || '-release_namespace'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
30
31 18 ▶ if ( $firstarg eq $take) {
Branch: 2 branches
BranchTrueFalseTotal
if ($firstarg eq $take) { } 7 11 18
elsif ($firstarg eq $release) { } 0 11 11
32 7 Class::MakeMethods::Emulator::namespace_capture($class, $emulation_target);
33 7 return 1;
34 } elsif ( $firstarg eq $release) {
35 0 Class::MakeMethods::Emulator::namespace_release($class, $emulation_target);
36 0 return 1;
37 }
38 }
39  
40 ########################################################################
41 ### NAMESPACE MUNGING: _namespace_capture(), _namespace_release()
42 ########################################################################
43  
44 10 ▶sub namespace_capture {
Subroutine namespace_capture: called CC=2 SCAR=6.9
Pod undocumented
45 10 my $source_package = shift;
46 10 my $target_package = shift;
47  
48 # warn "Mapping $source_package over $target_package \n";
49  
50 10 my $source_file = "$source_package.pm";
51 10 $source_file =~ s{::}{/}g;
52
53 10 my $target_file = "$target_package.pm";
54 10 $target_file =~ s{::}{/}g;
55
56 10 my $temp_package = $source_package . '::Target::' . $target_package;
57 10 my $temp_file = "$temp_package.pm";
58 10 $temp_file =~ s{::}{/}g;
59
60 21 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 10 ▶ unless ( ${$temp_package . "::TargetCaptured"} ++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (${$temp_package . '::TargetCaptured';}++) 10 0 10
62 10 *{$temp_package . "::"} = *{$target_package . "::"};
63 10 $::INC{$temp_file} = $::INC{$target_file};
64 }
65 10 *{$target_package . "::"} = *{$source_package . "::"};
66 10 $::INC{$target_file} = $::INC{$source_file}
67 }
68  
69 0 ▶sub namespace_release {
Subroutine namespace_release: not called CC=2 SCAR=14.8
Pod undocumented
70 0 my $source_package = shift;
71 0 my $target_package = shift;
72
73 0 my $target_file = "$target_package.pm";
74 0 $target_file =~ s{::}{/}g;
75
76 0 my $temp_package = $source_package . '::Target::' . $target_package;
77 0 my $temp_file = "$temp_package.pm";
78 0 $temp_file =~ s{::}{/}g;
79
80 21 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 0 ▶ unless ( ${"${temp_package}::TargetCaptured"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (${"${temp_package}::TargetCaptured";}) 0 0 0
82 0 Carp::croak("Can't _namespace_release: -take_namespace not called yet.");
83 }
84 0 *{$target_package . "::"} = *{$temp_package. "::"};
85 0 $::INC{$target_file} = $::INC{$temp_file};
86 }
87  
88 ########################################################################
89  
90 21 1;
91  
92 __END__
« blib/lib/Class/MakeMethods/Attribute.pm ↑ Summary blib/lib/Class/MakeMethods/Template/Universal.pm »