lib/Pod/Coverage/More/Declared/MOP.pm

filter: Statementstmt 100% 59 / 59 Branchbran 80.5% 29 / 36 Conditioncond 70.5% 12 / 17 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 87.3% 117 / 134 CC 27 SCAR 25.1
CC
27
Cov
89%
declarations
19.5
_metaclass
9.0
applies_to
2.0
CRAP 12.3
« lib/Pod/Coverage/More/Types.pm ↑ Summary lib/Test/Pod/Coverage/More.pm »
1 # ABSTRACT: Declarations of the attributes of Moose, Mouse and Moo classes
2 # PODNAME: Pod::Coverage::More::Declared::MOP
3  
4 package Pod::Coverage::More::Declared::MOP 0.003;
5  
6 13 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use warnings FATAL => q{all};
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use Pod::Coverage::More::Declared;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 ▶use Types::Standard qw{Bool InstanceOf};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use Types::TypeTiny qw{to_TypeTiny};
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 # Whether L<Moose>, L<Mouse> or L<Moo> built C<package>.
16 # @param package Str the name of the package
17 # @returns Bool
18 # @example next if !Pod::Coverage::More::Declared::MOP->applies_to('Some::Class');
19 42 ▶sub applies_to {
Subroutine applies_to: called CC=2 SCAR=6.9
Pod documented
20 42 my ( $class, $package ) = @_;
21 42 ▶ return _metaclass($package) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_metaclass($package) ? : 3 39 42
22 }
23  
24 # The metaclass of PACKAGE and the system that built it, or nothing.
25 45 ▶sub _metaclass {
Subroutine _metaclass: called CC=9 SCAR=22.0
26 45 my ($package) = @_;
27 45 ▶ if ( $INC{'Moo.pm'} && $package->isa('Moo::Object') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moo.pm"} and $package->isa("Moo::Object")) 2 43 45
Condition100%3/3
$INC{"Moo.pm"} and $package->isa("Moo::Object")
!ll&&!rl&&r
3582
MC/DC100%2/2
$INC{"Moo.pm"} and $package->isa("Moo::Object")
$INC{"Moo.pm"} $package->isa("Moo::Object")
Truth table100%3/3
A and B
A= $INC{"Moo.pm"}B= $package->isa("Moo::Object")
ABresult
0X0
100
111
28 2 require Moose;
29 2 return ( $package->meta, 'Moo' );
30 }
31 43 ▶ if ( $INC{'Class/MOP.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Class/MOP.pm"}) 10 33 43
32 10 my $meta = Class::MOP::class_of($package);
33 10 ▶ return ( $meta, 'Moose' ) if $meta && $meta->can('get_all_attributes');
Branch: 1 branch
BranchTrueFalseTotal
if $meta and $meta->can("get_all_attributes") 2 8 10
Condition66%2/3
$meta and $meta->can("get_all_attributes")
!ll&&!rl&&r
802
MC/DC50%1/2
$meta and $meta->can("get_all_attributes")
$meta $meta->can("get_all_attributes")
Truth table66%2/3
A and B
A= $metaB= $meta->can("get_all_attributes")
ABresult
0X0
100
111
34 }
35 41 ▶ if ( $INC{'Mouse.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Mouse.pm"}) 8 33 41
36 8 my $meta = Mouse::Util::class_of($package);
37 8 ▶ return ( $meta, 'Mouse' ) if $meta && $meta->can('get_all_attributes');
Branch: 1 branch
BranchTrueFalseTotal
if $meta and $meta->can("get_all_attributes") 2 6 8
Condition66%2/3
$meta and $meta->can("get_all_attributes")
!ll&&!rl&&r
602
MC/DC50%1/2
$meta and $meta->can("get_all_attributes")
$meta $meta->can("get_all_attributes")
Truth table66%2/3
A and B
A= $metaB= $meta->can("get_all_attributes")
ABresult
0X0
100
111
38 }
39 39 return;
40 }
41  
42 # The declarations of the subs of C<package> that C<names> lists, as L<Pod::Coverage::More::Declared> describes them.
43 # @param package Str the name of the package
44 # @param names ArrayRef[Str] the names of the subs
45 # @returns HashRef from the name of each declared sub to its declaration
46 # @example my $declared = Pod::Coverage::More::Declared::MOP->declarations( 'Some::Class', ['new'] );
47 3 ▶sub declarations {
Subroutine declarations: called CC=18 SCAR=29.7
Pod documented
48 3 my ( $class, $package, $names ) = @_;
49 3 my ( $meta, $via ) = _metaclass($package);
50 3 my %own = map { $_ => 1 } @$names;
51 3 my %declared;
52 my @named;
53  
54 3 foreach my $attr ( sort { $a->name cmp $b->name } $meta->get_all_attributes ) {
55 6 ▶ my $type = $attr->has_type_constraint ? to_TypeTiny( $attr->type_constraint ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$attr->has_type_constraint ? : 6 0 6
56 6 ▶ my %common = ( via => $via, attribute => $attr->name, documentation => $attr->can('documentation') ? $attr->documentation : undef );
Branch: 1 branch
BranchTrueFalseTotal
$attr->can('documentation') ? : 6 0 6
57 6 ▶ my @returned = $type ? ($type) : ();
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 6 0 6
58  
59 6 ▶ push @named, { name => undef, named => $attr->init_arg, type => $type, optional => $attr->is_required ? 0 : 1, invocant => 0 }
Branch: 2 branches
BranchTrueFalseTotal
if defined $attr->init_arg 6 0 6
$attr->is_required ? : 3 3 6
60 if defined $attr->init_arg;
61  
62 6 my $reader = $attr->get_read_method;
63 6 my $writer = $attr->get_write_method;
64 6 ▶ if ( defined $reader && defined $writer && $reader eq $writer ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reader and defined $writer and $reader eq $writer) { } 3 3 6
Condition66%4/6
defined $reader and defined $writer and $reader eq $writer
!ll&&!rl&&r
303
defined $reader and defined $writer
!ll&&!rl&&r
033
MC/DC33%1/3
defined $reader and defined $writer and $reader eq $writer
defined $reader defined $writer $reader eq $writer
Truth table50%2/4
A and B and C
A= defined $readerB= defined $writerC= $reader eq $writer
ABCresult
0XX0
10X0
1100
1111
65 3 $declared{$reader} = { %common, role => 'accessor', params => [ _self(), _value( $type, 1 ) ], returns => [@returned] };
66 }
67 else {
68 3 ▶ $declared{$reader} = { %common, role => 'reader', params => [ _self() ], returns => [@returned] } if defined $reader;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reader 3 0 3
69 3 ▶ $declared{$writer} = { %common, role => 'writer', params => [ _self(), _value( $type, 0 ) ], returns => [@returned] } if defined $writer;
Branch: 1 branch
BranchTrueFalseTotal
if defined $writer 0 3 3
70 }
71 6 ▶ $declared{ $attr->predicate } = { %common, role => 'predicate', params => [ _self() ], returns => [Bool] } if $attr->predicate;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->predicate 3 3 6
72 6 ▶ $declared{ $attr->clearer } = { %common, role => 'clearer', params => [ _self() ], returns => [] } if $attr->clearer;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->clearer 1 5 6
73 }
74  
75 $declared{new} = {
76 3 via => $via,
77 role => 'constructor',
78 params => [ Pod::Coverage::More::Declared->invocant, @named ],
79 returns => [ InstanceOf [$package] ],
80 };
81  
82 3 foreach my $name (@$names) {
83 16 ▶ my $method = $meta->get_method($name) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $method = $meta->get_method($name) or next 16 0 16
84 16 ▶ next if !$method->isa('Class::MOP::Method::Wrapped');
Branch: 1 branch
BranchTrueFalseTotal
unless $method->isa("Class::MOP::Method::Wrapped") 15 1 16
85 1 ▶ $declared{$name} //= { via => $via, role => 'method', params => [], returns => [] };
Condition50%1/2
$declared{$name} //= {"via", $via, "role", "method", "params", [], "returns", []}
l!l
01
MC/DC0%0/1
$declared{$name} //= {"via", $via, "role", "method", "params", [], "returns", []}
$declared{$name}
Truth table50%1/2
A
A= $declared{$name}
Aresult
11
00
86 1 $declared{$name}{body} = $method->get_original_method->body;
87 }
88  
89 3 delete @declared{ grep { !$own{$_} } keys %declared };
90 3 return \%declared;
91 }
92  
93 10 ▶sub _self {
Subroutine _self: called CC=1 SCAR=0.0
94 10 return Pod::Coverage::More::Declared->invocant;
95 }
96  
97 3 ▶sub _value {
Subroutine _value: called CC=1 SCAR=0.0
98 3 my ( $type, $optional ) = @_;
99 3 return { name => undef, index => 1, type => $type, optional => $optional, invocant => 0 };
100 }
101  
102 13 1;
103  
104 __END__
« lib/Pod/Coverage/More/Types.pm ↑ Summary lib/Test/Pod/Coverage/More.pm »