Generator.pm

filter: Statementstmt 100% 62 / 62 Branchbran 100% 20 / 20 Conditioncond 84.6% 11 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 94.9% 113 / 119 CC 16 SCAR 18.6
CC
16
Cov
98%
new_package
12.0
assign_symbols
5.0
BEGIN
1.0
CRAP 6.4
↑ Summary Reaper.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Package::Generator;
4 {
5 4 $Package::Generator::VERSION = '1.106';
6 }
7 4 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # ABSTRACT: generate new packages quickly and easily
9  
10 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 4 my $i = 0;
15 10 ▶my $unique_part = sub { $i++ };
Subroutine __ANON__: called CC=1 SCAR=0.0
16 19 ▶my $make_unique = sub { sprintf "%s::%u", $_[0], $_[1]->() };
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 22 ▶sub new_package {
Subroutine new_package: called CC=12 SCAR=24.9
Pod documented
19 22 my ($self, $arg) = @_;
20 22 ▶ $arg->{base} ||= 'Package::Generator::__GENERATED__';
Condition100%2/2
$arg->{"base"} ||= "Package::Generator::__GENERATED__"
l!l
517
MC/DC100%1/1
$arg->{"base"} ||= "Package::Generator::__GENERATED__"
$arg->{"base"}
Truth table100%2/2
A
A= $arg->{"base"}
Aresult
11
00
21 22 ▶ $arg->{unique_part} ||= $unique_part;
Condition66%2/3
$arg->{"unique_part"} ||= $unique_part
l!l&&r!l&&!r
5170
MC/DC0%0/2
$arg->{"unique_part"} ||= $unique_part
$arg->{"unique_part"} $unique_part
Truth table66%2/3
A ||= B
A= $arg->{"unique_part"}B= $unique_part
ABresult
1X1
011
000
22 22 ▶ $arg->{make_unique} ||= $make_unique;
Condition66%2/3
$arg->{"make_unique"} ||= $make_unique
l!l&&r!l&&!r
7150
MC/DC0%0/2
$arg->{"make_unique"} ||= $make_unique
$arg->{"make_unique"} $make_unique
Truth table66%2/3
A ||= B
A= $arg->{"make_unique"}B= $make_unique
ABresult
1X1
011
000
23 22 ▶ $arg->{max_tries} ||= 1;
Condition100%2/2
$arg->{"max_tries"} ||= 1
l!l
319
MC/DC100%1/1
$arg->{"max_tries"} ||= 1
$arg->{"max_tries"}
Truth table100%2/2
A
A= $arg->{"max_tries"}
Aresult
11
00
24  
25 22 my $package;
26 22 for (my $i = 1; 1; $i++) {
27 26 $package = $arg->{make_unique}->($arg->{base}, $arg->{unique_part});
28 26 ▶ last unless $self->package_exists($package);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->package_exists($package) 19 7 26
29 Carp::croak "couldn't generate a pristene package under $arg->{base}"
30 7 ▶ if $i >= $arg->{max_tries};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $arg->{"max_tries"} 3 4 7
31 }
32  
33 19 ▶ my @data = $arg->{data} ? @{ $arg->{data} } : ();
Branch: 1 branch
BranchTrueFalseTotal
$arg->{'data'} ? : 2 17 19
34  
35 push @data, (
36 ($arg->{isa} ? (ISA => (ref $arg->{isa} ? $arg->{isa} : [ $arg->{isa} ]))
37 : ()),
38 19 ▶ ($arg->{version} ? (VERSION => $arg->{version}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
$arg->{'isa'} ? : 2 17 19
ref $arg->{'isa'} ? : 1 1 2
$arg->{'version'} ? : 1 18 19
39 );
40  
41 19 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 5 14 19
42 5 $self->assign_symbols($package, \@data);
43 } else {
44 # This ensures that even without symbols, the package is created so that it
45 # will not be detected as pristene by package_exists. Without this line of
46 # code, non-unique tests will fail. -- rjbs, 2006-04-14
47 {
48 ## no critic (ProhibitNoStrict)
49 4 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
50 4 ▶ no warnings qw(void);
Subroutine BEGIN: called CC=1 SCAR=0.0
51 14 %{$package . '::'};
52 }
53 }
54  
55 18 return $package;
56 }
57  
58  
59 5 ▶sub assign_symbols {
Subroutine assign_symbols: called CC=5 SCAR=16.1
Pod documented
60 5 my ($self, $package, $key_value_pairs) = @_;
61  
62 5 ▶ Carp::croak "list of key/value pairs must be even!" if @$key_value_pairs % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$key_value_pairs % 2 1 4 5
63  
64 ## no critic (ProhibitNoStrict)
65 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 4 ▶ while (my ($name, $value) = splice @$key_value_pairs, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@$key_value_pairs, 0, 2)) 11 4 15
67 11 my $full_name = "$package\:\:$name";
68  
69 11 ▶ if (!ref($value) or Scalar::Util::blessed($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $value or builtin::blessed($value)) { } 6 5 11
Condition100%3/3
not ref $value or builtin::blessed($value)
l!l&&r!l&&!r
515
MC/DC100%2/2
not ref $value or builtin::blessed($value)
not ref $value builtin::blessed($value)
Truth table100%3/3
not(A) or B
A= not ref $valueB= builtin::blessed($value)
ABresult
1X1
011
000
70 6 ${$full_name} = $value;
71 } else {
72 5 *{$full_name} = $value;
73 }
74 }
75 }
76  
77  
78 39 ▶sub package_exists {
Subroutine package_exists: called CC=1 SCAR=0.0
Pod documented
79 39 my ($self, $package) = @_;
80  
81 39 return defined *{$package . '::'};
82 }
83  
84 # My first attempt! How silly I felt when I threw in some Data::Dumper and saw
85 # that the above would suffice. -- rjbs, 2006-04-14
86 #
87 # my @parts = split /::/, $package;
88 #
89 # my $current_pkg = 'main';
90 # for (@parts) {
91 # my $current_stash = do { no strict 'refs'; \%{$current_pkg . "::"} };
92 # return unless exists $current_stash->{$_ . "::"};
93 # $current_pkg .= "::$_"
94 # }
95 # return 1;
96  
97 4 1;
98  
99 __END__
↑ Summary Reaper.pm »