MouseX/NativeTraits/MethodProvider.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 83.3% 10 / 12 Conditioncond 77.7% 7 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 90.0% 9 / 10 Podpod 75.0% 3 / 4 totaltotal 84.3% 70 / 83 CC 10 SCAR 15.1
CC
10
Cov
88%
argument_error
9.3
generate
2.0
get_generators
2.0
CRAP 4.5
« MouseX/NativeTraits/MethodProvider/HashRef.pm ↑ Summary MouseX/NativeTraits/MethodProvider/ArrayRef.pm »
1 package MouseX::NativeTraits::MethodProvider;
2 19 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 19 has attr => (
5 is => 'ro',
6 isa => 'Object',
7 required => 1,
8 weak_ref => 1,
9 );
10  
11 19 has reader => (
12 is => 'ro',
13  
14 lazy_build => 1,
15 );
16  
17 19 has writer => (
18 is => 'ro',
19  
20 lazy_build => 1,
21 );
22  
23 62 ▶sub _build_reader {
Subroutine _build_reader: called CC=1 SCAR=0.0
24 62 my($self) = @_;
25 62 return $self->attr->get_read_method_ref;
26 }
27  
28 53 ▶sub _build_writer {
Subroutine _build_writer: called CC=1 SCAR=0.0
29 53 my($self) = @_;
30 53 return $self->attr->get_write_method_ref;
31 }
32  
33 527 ▶sub has_generator {
Subroutine has_generator: called CC=1 SCAR=0.0
Pod documented
34 527 my($self, $name) = @_;
35 527 return $self->meta->has_method("generate_$name");
36 }
37  
38 526 ▶sub generate {
Subroutine generate: called CC=2 SCAR=6.9
Pod documented
39 526 my($self, $handle_name, $method_to_call) = @_;
40  
41 526 my @curried_args;
42 526 ($method_to_call, @curried_args) = @{$method_to_call};
43  
44 526 my $code = $self->meta
45 ->get_method_body("generate_$method_to_call")->($self);
46  
47 526 ▶ if(@curried_args){
Branch: 1 branch
BranchTrueFalseTotal
if (@curried_args) { } 171 355 526
48 23 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine unshift_curried: called CC=1 SCAR=0.0
49 23 my $instance = shift;
50 23 $code->($instance, @curried_args, @_);
51 171 };
52 }
53 else{
54 355 return $code;
55 }
56 }
57  
58 0 ▶sub get_generators {
Subroutine get_generators: not called CC=1 SCAR=6.9
Pod documented
59 0 my($self) = @_;
60  
61 0 return grep{ s/\A generate_ //xms } $self->meta->get_method_list;
62 }
63  
64 620 ▶sub argument_error {
Subroutine argument_error: called CC=9 SCAR=22.3
Pod undocumented
65 620 my($self, $name, $min, $max, $nargs) = @_;
66  
67 620 ▶ if(not defined $max) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $max) 10 610 620
68 10 $max = 9 ** 9 ** 9; # inifinity :p
69 }
70  
71 # fix numbers for $self
72 620 $min--;
73 620 $max--;
74 620 $nargs--;
75  
76 620 ▶ if($min <= $nargs and $nargs <= $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min <= $nargs and $nargs <= $max) 0 620 620
Condition66%2/3
$min <= $nargs and $nargs <= $max
!ll&&!rl&&r
1105100
MC/DC0%0/2
$min <= $nargs and $nargs <= $max
$min <= $nargs $nargs <= $max
Truth table66%2/3
A and B
A= $min <= $nargsB= $nargs <= $max
ABresult
0X0
100
111
77 0 Carp::croak("Oops ($name): nags=$nargs, min=$min, max=$max");
78 }
79  
80 620 my $message = 'Cannot call %s %s argument%s';
81  
82 620 ▶ if($min == 0 and $max == 0 && $nargs > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min == 0 and ($max == 0 and $nargs > 0)) 180 440 620
Condition83%5/6
$min == 0 and ($max == 0 and $nargs > 0)
!ll&&!rl&&r
39050180
$max == 0 and $nargs > 0
!ll&&!rl&&r
500180
MC/DC66%2/3
$min == 0 and ($max == 0 and $nargs > 0)
$min == 0 $max == 0 $nargs > 0
Truth table75%3/4
A and B and C
A= $min == 0B= $max == 0C= $nargs > 0
ABCresult
0XX0
10X0
1100
1111
83 180 $self->meta->throw_error(
84 sprintf $message,
85 $name, 'with any', 's' );
86 }
87  
88 $self->meta->throw_error(
89 440 ▶ sprintf 'Cannot call %s %s %d argument%s',
Branch: 2 branches
BranchTrueFalseTotal
$nargs < $min ? : 110 330 440
$nargs == 1 ? : 0 440 440
90 $name, ($nargs < $min
91 ? ('without at least', $min)
92 : ('with more than', $max) ),
93 $nargs == 1 ? '' : 's' );
94 }
95  
96 19 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 19 __PACKAGE__->meta->make_immutable(strict_constructor => 1);
98  
99 __END__
« MouseX/NativeTraits/MethodProvider/HashRef.pm ↑ Summary MouseX/NativeTraits/MethodProvider/ArrayRef.pm »