| 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.001; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use 5.036; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use warnings FATAL => q{all}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Pod::Coverage::More::Declared; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Types::Standard qw{Bool InstanceOf}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | 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 | 37 | ▶ | sub applies_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 37 | my ( $class, $package ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 37 | ▶ | return _metaclass($package) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # The metaclass of PACKAGE and the system that built it, or nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 40 | ▶ | sub _metaclass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_metaclass: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 40 | my ($package) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 40 | ▶ | if ( $INC{'Moo.pm'} && $package->isa('Moo::Object') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$INC{"Moo.pm"} and $package->isa("Moo::Object")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | require Moose; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | return ( $package->meta, 'Moo' ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 38 | ▶ | if ( $INC{'Class/MOP.pm'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | my $meta = Class::MOP::class_of($package); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | return ( $meta, 'Moose' ) if $meta && $meta->can('get_all_attributes'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$meta and $meta->can("get_all_attributes")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 36 | ▶ | if ( $INC{'Mouse.pm'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | my $meta = Mouse::Util::class_of($package); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | return ( $meta, 'Mouse' ) if $meta && $meta->can('get_all_attributes'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$meta and $meta->can("get_all_attributes")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 34 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | my %common = ( via => $via, attribute => $attr->name, documentation => $attr->can('documentation') ? $attr->documentation : undef ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | my @returned = $type ? ($type) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | push @named, { name => undef, named => $attr->init_arg, type => $type, optional => $attr->is_required ? 0 : 1, invocant => 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
defined $reader and defined $writer and $reader eq $writer
defined $reader and defined $writer
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | $declared{$writer} = { %common, role => 'writer', params => [ _self(), _value( $type, 0 ) ], returns => [@returned] } if defined $writer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | ▶ | $declared{ $attr->predicate } = { %common, role => 'predicate', params => [ _self() ], returns => [Bool] } if $attr->predicate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | $declared{ $attr->clearer } = { %common, role => 'clearer', params => [ _self() ], returns => [] } if $attr->clearer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | next if !$method->isa('Class::MOP::Method::Wrapped'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | $declared{$name} //= { via => $via, role => 'method', params => [], returns => [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$declared{$name} //= {"via", $via, "role", "method", "params", [], "returns", []}
MC/DC0%0/1
$declared{$name} //= {"via", $via, "role", "method", "params", [], "returns", []}
$declared{$name}
Truth table50%1/2
A
A= $declared{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||||||||||||||||