blib/lib/MooseX/Prototype.pm

filter: Statementstmt 81.5% 93 / 114 Branchbran 40.9% 9 / 22 Conditioncond 50.0% 11 / 22 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 85.7% 24 / 28 Podpod 0.0% 0 / 2 totaltotal 68.6% 138 / 201 CC 23 SCAR 23.2
CC
23
Cov
72%
extend
56.0
__ANON__
6.0
_build_create_class_from_prototype
5.4
CRAP 10.2
↑ Summary
1 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Moose 2.00 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Data::OptList 0 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Sub::Exporter 0 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 my $serial = 0;
10 5 ▶my $serial_name = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
11 5 sprintf('MooseX::Prototype::__ANON__::%04d', ++$serial);
12 3 };
13  
14 2 ▶my $mk_attribute = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
15 2 my ($name, $rw) = @_;
16 2 ▶ Moose::Meta::Attribute::->new($name, is => ($rw||'rw'), isa => 'Any');
Condition50%1/2
$rw || 'rw'
l!l
20
MC/DC0%0/1
$rw || 'rw'
$rw
Truth table50%1/2
A
A= $rw
Aresult
11
00
17 3 };
18  
19 6 ▶my $cloned_attributes = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
20 return [
21 map {
22 6 my $attr = $_;
23 12 my @clone = ();
24 12 ▶ if ($attr->has_value($_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->has_value($_[0])) 10 2 12
25 {
26 10 my $value = $attr->get_value($_[0]);
27 10 ▶ @clone = ( default => sub{$value} );
Subroutine __ANON__: called CC=1 SCAR=0.0
28 }
29 12 $attr->clone(@clone);
30 } $_[0]->meta->get_all_attributes
31 ]
32 3 };
33  
34 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.1
35 package MooseX::Prototype;
36 3 our $AUTHORITY = 'cpan:TOBYINK';
37 3 our $VERSION = '0.004';
38 3 $INC{'MooseX/Prototype.pm'} = __FILE__;
39  
40 3 ▶ use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 exports => [
42 create_class_from_prototype => \&_build_create_class_from_prototype,
43 object => \&_build_object,
44 ],
45 groups => {
46 default => [qw/ object /],
47 },
48 3 };
49
50 sub _build_create_class_from_prototype
51 4 ▶ {
Subroutine _build_create_class_from_prototype: called CC=5 SCAR=16.9
52 4 my ($class, $name, $arg) = @_;
53
54 4 ▶ my $IS = $arg->{ -is } || 'rw';
Condition50%1/2
$arg->{'-is'} || 'rw'
l!l
04
MC/DC0%0/1
$arg->{'-is'} || 'rw'
$arg->{'-is'}
Truth table50%1/2
A
A= $arg->{'-is'}
Aresult
11
00
55 4 ▶ my $BASE = $arg->{ -base } || 'Moose::Object';
Condition50%1/2
$arg->{'-base'} || 'Moose::Object'
l!l
04
MC/DC0%0/1
$arg->{'-base'} || 'Moose::Object'
$arg->{'-base'}
Truth table50%1/2
A
A= $arg->{'-base'}
Aresult
11
00
56 my $ROLE = $arg->{ -role } || (
57 4 ▶ $IS eq 'ro'
Branch: 1 branch
BranchTrueFalseTotal
$IS eq 'ro' ? : 0 4 4
Condition33%1/3
$arg->{'-role'} || ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
l!l&&r!l&&!r
040
MC/DC0%0/2
$arg->{'-role'} || ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
$arg->{'-role'} ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
Truth table33%1/3
A || B
A= $arg->{'-role'}B= ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
ABresult
1X1
011
000
58 ? 'MooseX::Prototype::Trait::Object::RO'
59 : 'MooseX::Prototype::Trait::Object::RW'
60 );
61
62 return sub
63 6 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.0
64 6 my ($instance, $opts) = @_;
65 6 ▶ $opts = { name => $opts } if defined $opts && !ref $opts;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts and not ref $opts 2 4 6
Condition66%2/3
defined $opts and not ref $opts
!ll&&!rl&&r
402
MC/DC50%1/2
defined $opts and not ref $opts
defined $opts not ref $opts
Truth table66%2/3
A and not(B)
A= defined $optsB= not ref $opts
ABresult
0X0
100
111
66
67 6 ▶ $opts->{name} ||= $serial_name->();
Condition66%2/3
$opts->{"name"} ||= &$serial_name()
l!l&&r!l&&!r
240
MC/DC0%0/2
$opts->{"name"} ||= &$serial_name()
$opts->{"name"} &$serial_name()
Truth table66%2/3
A ||= B
A= $opts->{"name"}B= &$serial_name()
ABresult
1X1
011
000
68
69 Moose::Meta::Class::->create(
70 $opts->{name},
71 6 superclasses => [ ref $instance ],
72 roles => [ $ROLE ],
73 attributes => $instance->$cloned_attributes,
74 );
75 6 return $opts->{name};
76 }
77 4 }
78
79 sub _build_object
80 5 ▶ {
Subroutine _build_object: called CC=5 SCAR=16.8
81 5 my ($class, $name, $arg) = @_;
82
83 5 ▶ my $IS = $arg->{ -is } || 'rw';
Condition50%1/2
$arg->{'-is'} || 'rw'
l!l
05
MC/DC0%0/1
$arg->{'-is'} || 'rw'
$arg->{'-is'}
Truth table50%1/2
A
A= $arg->{'-is'}
Aresult
11
00
84 5 ▶ my $BASE = $arg->{ -base } || 'Moose::Object';
Condition50%1/2
$arg->{'-base'} || 'Moose::Object'
l!l
05
MC/DC0%0/1
$arg->{'-base'} || 'Moose::Object'
$arg->{'-base'}
Truth table50%1/2
A
A= $arg->{'-base'}
Aresult
11
00
85 my $ROLE = $arg->{ -role } || (
86 5 ▶ $IS eq 'ro'
Branch: 1 branch
BranchTrueFalseTotal
$IS eq 'ro' ? : 0 5 5
Condition33%1/3
$arg->{'-role'} || ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
l!l&&r!l&&!r
050
MC/DC0%0/2
$arg->{'-role'} || ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
$arg->{'-role'} ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
Truth table33%1/3
A || B
A= $arg->{'-role'}B= ($IS eq 'ro' ? 'MooseX::Prototype::Trait::Object::RO' : 'MooseX::Prototype::Trait::Object::RW')
ABresult
1X1
011
000
87 ? 'MooseX::Prototype::Trait::Object::RO'
88 : 'MooseX::Prototype::Trait::Object::RW'
89 );
90
91 return sub ($)
92 1 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
93 1 ▶ my $hash = ref $_[0] ? shift : +{@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 0 1
94 my $class = Moose::Meta::Class::->create(
95 $serial_name->(),
96 superclasses => [ $BASE ],
97 roles => [ $ROLE ],
98 attributes => [
99 2 map { $mk_attribute->($_, $IS) }
100 3 grep { not /^\&/ }
101 keys %$hash
102 ],
103 methods => {
104 1 map { ; substr($_, 1) => $hash->{$_} }
105 1 grep { /^\&/ }
106 keys %$hash
107 },
108 );
109 return $class->name->new({
110 2 map { ; $_ => $hash->{$_} }
111 1 grep { not /^\&/ }
112 keys %$hash
113 });
114 }
115 5 }
116
117 3 *create_class_from_prototype = __PACKAGE__->_build_create_class_from_prototype;
118 3 *object = __PACKAGE__->_build_object;
119 };
120  
121 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.1
122 package MooseX::Prototype::Trait::Object;
123 3 our $AUTHORITY = 'cpan:TOBYINK';
124 3 our $VERSION = '0.004';
125 3 $INC{'MooseX/Prototype/Trait/Object.pm'} = __FILE__;
126
127 3 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
128
129 4 ▶ sub create_class { goto \&MooseX::Prototype::create_class_from_prototype };
Subroutine create_class: called CC=1 SCAR=0.0
Pod undocumented
130
131 3 requires '_attribute_accessor_type';
132
133 19 ▶ around new => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
134 19 my ($orig, $class, @args) = @_;
135 19 ▶ if (ref $class)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 2 17 19
136 {
137 2 return $class->create_class->new(@args);
138 }
139 17 $class->$orig(@args);
140 3 };
141
142 0 ▶ around [qw/ does DOES /] => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
143 0 my ($orig, $self, $role) = @_;
144 0 ▶ return 1 if $role eq -proto;
Branch: 1 branch
BranchTrueFalseTotal
if $role eq "-proto" 0 0 0
145 0 return $self->$orig($role);
146 3 };
147
148 0 ▶ sub extend {
Subroutine extend: not called CC=7 SCAR=40.3
Pod undocumented
149 0 my $self = shift;
150 0 ▶ my $hash = ref($_[0]) ? $_[0] : +{@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
151 my $extension = Moose::Meta::Class::->create(
152 $serial_name->(),
153 superclasses => [ ref $self ],
154 attributes => [
155 0 map { $mk_attribute->($_) }
156 0 grep { not /^\&/ }
157 keys %$hash
158 ],
159 methods => {
160 0 map { ; substr($_, 1) => $hash->{$_} }
161 0 grep { /^\&/ }
162 keys %$hash
163 },
164 );
165 0 bless $self, $extension->name;
166 0 ▶ if ($self->DOES('MooseX::Prototype::Trait::Object::RO'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->DOES('MooseX::Prototype::Trait::Object::RO')) { } 0 0 0
167 {
168 0 foreach my $key (keys %$hash)
169 {
170 0 ▶ next if $key =~ /^\&/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^\&/ 0 0 0
171 # breaks Moose encapsulation :-(
172 0 $self->{$key} = $hash->{$key};
173 }
174 }
175 else
176 {
177 0 foreach my $key (keys %$hash)
178 {
179 0 ▶ next if $key =~ /^\&/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^\&/ 0 0 0
180 0 $self->$key($hash->{$key});
181 }
182 }
183 0 return $self;
184 }
185 };
186  
187 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
188 package MooseX::Prototype::Trait::Object::RO;
189 3 our $AUTHORITY = 'cpan:TOBYINK';
190 3 our $VERSION = '0.004';
191 3 $INC{'MooseX/Prototype/Trait/Object/RO.pm'} = __FILE__;
192 3 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 3 with qw( MooseX::Prototype::Trait::Object );
194 0 ▶ sub _attribute_accessor_type { 'ro' };
Subroutine _attribute_accessor_type: not called CC=1 SCAR=6.9
195 };
196  
197 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
198 package MooseX::Prototype::Trait::Object::RW;
199 3 our $AUTHORITY = 'cpan:TOBYINK';
200 3 our $VERSION = '0.004';
201 3 $INC{'MooseX/Prototype/Trait/Object/RW.pm'} = __FILE__;
202 3 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
203 3 with qw( MooseX::Prototype::Trait::Object );
204 0 ▶ sub _attribute_accessor_type { 'rw' };
Subroutine _attribute_accessor_type: not called CC=1 SCAR=6.9
205 };
206  
207 3 1;
208  
209 __END__
↑ Summary