Data/GeneratorSub.pm

filter: Statementstmt 71.7% 28 / 39 Branchbran 55.5% 10 / 18 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 60.0% 48 / 80 CC 13 SCAR 20.2
CC
13
Cov
60%
new
15.3
_merge_params
5.8
compile
4.8
CRAP 7.5
« Data/Plugin/SQLTypes.pm ↑ Summary Data/Util.pm »
1 package Mock::Data::GeneratorSub;
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 require Mock::Data::Generator;
5 12 our @ISA= qw( Mock::Data::Generator );
6  
7 # ABSTRACT: Wrap a coderef to become a blessed Generator object
8 12 our $VERSION = '0.04'; # VERSION
9  
10  
11 72 ▶sub new {
Subroutine new: called CC=6 SCAR=27.3
Pod documented
12 72 my ($class, $coderef, @params)= @_;
13 72 ▶ if (ref $coderef eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $coderef eq "HASH") 0 72 72
14 0 ▶ @params= @{ $coderef->{params} || [] };
Condition0%0/2
$coderef->{'params'} || []
l!l
00
MC/DC0%0/1
$coderef->{'params'} || []
$coderef->{'params'}
Truth table0%0/2
A
A= $coderef->{'params'}
Aresult
11
00
15 0 $coderef= $coderef->{coderef};
16 }
17 72 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 72 72
18 0 ▶ $coderef ||= $class->{coderef};
Condition0%0/3
$coderef ||= $class->{"coderef"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$coderef ||= $class->{"coderef"}
$coderef $class->{"coderef"}
Truth table0%0/3
A ||= B
A= $coderefB= $class->{"coderef"}
ABresult
1X1
011
000
19 0 @params= $class->_merge_params(@params);
20 0 $class= ref $class;
21 }
22 72 ▶ Scalar::Util::reftype($coderef) eq 'CODE' or Carp::croak("Not a coderef");
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($coderef) eq "CODE" or Carp::croak("Not a coderef") 72 0 72
23 72 bless {
24 coderef => $coderef,
25 params => \@params,
26 }, $class;
27 }
28  
29 190 ▶sub _merge_params {
Subroutine _merge_params: called CC=5 SCAR=17.5
30 190 my $self= shift;
31 190 my $p= $self->{params};
32 190 ▶ my $named_p= ref $p->[0] eq 'HASH'? $p->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $p->[0] eq 'HASH' ? : 0 190 190
33 # Merge any options-by-name newly supplied with options-by-name from @params
34 0 ▶ unshift @_, (ref $_[0] eq 'HASH')? { %$named_p, %{shift @_} } : $named_p
Branch: 2 branches
BranchTrueFalseTotal
if $named_p 0 190 190
ref $_[0] eq 'HASH' ? : 0 0 0
35 if $named_p;
36 # Append positional params if none provided
37 190 ▶ push @_, @{$p}[1..$#$p]
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 189 1 190
38 unless @_ > 1;
39 190 return @_;
40 }
41  
42  
43 191 ▶sub generate {
Subroutine generate: called CC=2 SCAR=6.9
Pod documented
44 191 my ($self, $mock)= (shift, shift);
45 191 ▶ $self->{coderef}->($mock, @_? $self->_merge_params(@_) : @{$self->{params}});
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 190 1 191
46 }
47  
48  
49 38 ▶sub compile {
Subroutine compile: called CC=3 SCAR=15.7
Pod documented
50 38 my $self= shift;
51 38 my $params= $self->{params};
52 38 ▶ return $self->{coderef} unless @_ || @$params;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ or @$params 38 0 38
Condition33%1/3
@_ or @$params
l!l&&r!l&&!r
0038
MC/DC0%0/2
@_ or @$params
@_ @$params
Truth table33%1/3
A or B
A= @_B= @$params
ABresult
1X1
011
000
53 0 my @new_params= $self->_merge_params(@_);
54 0 my $coderef= $self->{coderef};
55 0 ▶ return sub { $coderef->(shift, @new_params) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 }
57  
58 12 1;
59  
60 __END__
« Data/Plugin/SQLTypes.pm ↑ Summary Data/Util.pm »