blib/lib/Pod/Coverage/Moose.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 82.9% 68 / 82 CC 10 SCAR 14.8
CC
10
Cov
86%
BUILD
6.2
__ANON__
5.6
BEGIN
1.0
CRAP 4.4
↑ Summary
1 package Pod::Coverage::Moose; # git description: v0.07-13-g19d14b4
2 # ABSTRACT: Pod::Coverage extension for Moose
3 # KEYWORDS: pod coverage verification validity tests documentation completeness moose methods inheritance
4 # vim: set ts=8 sts=4 sw=4 tw=115 et :
5  
6 3 our $VERSION = '0.08';
7  
8 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Pod::Coverage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Class::Load qw( load_class );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 #pod =head1 SYNOPSIS
18 #pod
19 #pod use Pod::Coverage::Moose;
20 #pod
21 #pod my $pcm = Pod::Coverage::Moose->new(package => 'MoosePackage');
22 #pod print 'Coverage: ', $pcm->coverage, "\n";
23 #pod
24 #pod =head1 DESCRIPTION
25 #pod
26 #pod When using L<Pod::Coverage> in combination with L<Moose>, it will
27 #pod report any method imported from a L<role|Moose::Role>. This is especially bad when
28 #pod used in combination with L<Test::Pod::Coverage>, since it takes away
29 #pod its ease of use.
30 #pod
31 #pod To use this module in combination with L<Test::Pod::Coverage>, use
32 #pod something like this:
33 #pod
34 #pod use Test::Pod::Coverage;
35 #pod all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::Moose'});
36 #pod
37 #pod =head1 ATTRIBUTES
38 #pod
39 #pod =head2 package
40 #pod
41 #pod This is the package used for inspection.
42 #pod
43 #pod =cut
44  
45 3 has package => (
46 is => 'rw',
47 isa => 'Str',
48 required => 1,
49 );
50  
51 #pod =head2 cover_requires
52 #pod
53 #pod Boolean flag to indicate that C<requires $method> declarations in a Role should be trusted.
54 #pod
55 #pod =cut
56  
57 3 has cover_requires => (
58 is => 'ro',
59 isa => 'Bool',
60 default => 0,
61 );
62  
63 #
64 # original pod_coverage object
65 #
66  
67 3 has _pod_coverage => (
68 is => 'rw',
69 isa => 'Pod::Coverage',
70 handles => [qw( coverage why_unrated naked uncovered covered )],
71 );
72  
73 #pod =head1 METHODS
74 #pod
75 #pod =head2 meta
76 #pod
77 #pod L<Moose> meta object.
78 #pod
79 #pod =head2 BUILD
80 #pod
81 #pod =for stopwords initialises
82 #pod
83 #pod Initialises the internal L<Pod::Coverage> object. It uses the meta object
84 #pod to find all methods and attribute methods imported via roles.
85 #pod
86 #pod =cut
87  
88 3 my %is = map { $_ => 1 } qw( rw ro wo );
89 3 ▶sub BUILD {
Subroutine BUILD: called CC=6 SCAR=18.2
Pod documented
90 3 my ($self, $args) = @_;
91  
92 3 my $meta = $self->package->meta;
93 3 ▶ my @trustme = @{ $args->{trustme} || [] };
Condition50%1/2
$args->{'trustme'} || []
l!l
03
MC/DC0%0/1
$args->{'trustme'} || []
$args->{'trustme'}
Truth table50%1/2
A
A= $args->{'trustme'}
Aresult
11
00
94  
95 3 push @trustme, qr/^meta$/;
96 push @trustme, # MooseX-AttributeHelpers hack
97 0 map { qr/^$_$/ }
98 0 map { $_->name }
99 3 ▶ grep { $_->isa('MooseX::AttributeHelpers::Meta::Method::Provided') }
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->isa("Moose::Meta::Role") 3 0 3
100 $meta->get_all_methods
101 unless $meta->isa('Moose::Meta::Role');
102 push @trustme,
103 13 map { qr/^\Q$_\E$/ } # turn value into a regex
104 map { # iterate over all roles of the class
105 3 my $role = $_;
106 $role->get_method_list,
107 ($self->cover_requires ? ($role->get_required_method_list) : ()),
108 map { # iterate over attributes
109 3 ▶ my $attr = $role->get_attribute($_);
Branch: 1 branch
BranchTrueFalseTotal
$self->cover_requires ? : 1 2 3
110 ($attr->{is} && $is{$attr->{is}} ? $_ : ()), # accessors
111 2 ▶ grep defined, map { $attr->{ $_ } } # other attribute methods
Branch: 1 branch
BranchTrueFalseTotal
$attr->{'is'} && $is{$attr->{'is'}} ? : 1 1 2
Condition66%2/3
$attr->{"is"} and $is{$attr->{"is"}}
!ll&&!rl&&r
101
MC/DC50%1/2
$attr->{"is"} and $is{$attr->{"is"}}
$attr->{"is"} $is{$attr->{"is"}}
Truth table66%2/3
A and B
A= $attr->{"is"}B= $is{$attr->{"is"}}
ABresult
0X0
100
111
112 qw( clearer predicate reader writer accessor );
113 } $role->get_attribute_list,
114 }
115 $meta->calculate_all_roles;
116  
117 3 $args->{trustme} = \@trustme;
118  
119 3 $self->_pod_coverage(Pod::Coverage->new(%$args));
120 }
121  
122 #pod =head1 DELEGATED METHODS
123 #pod
124 #pod Delegated to the traditional L<Pod::Coverage> object are:
125 #pod
126 #pod =head2 coverage
127 #pod
128 #pod =head2 covered
129 #pod
130 #pod =head2 naked
131 #pod
132 #pod =head2 uncovered
133 #pod
134 #pod =head2 why_unrated
135 #pod
136 #pod =head1 EXTENDED METHODS
137 #pod
138 #pod =head2 new
139 #pod
140 #pod The constructor will only return a C<Pod::Coverage::Moose> object if it
141 #pod is invoked on a class that C<can> a C<meta> method. Otherwise, a
142 #pod traditional L<Pod::Coverage> object will be returned. This is done so you
143 #pod don't get in trouble for mixing L<Moose> with non Moose classes in your
144 #pod project.
145 #pod
146 #pod =cut
147  
148 4 ▶around new => sub {
Subroutine __ANON__: called CC=5 SCAR=17.3
149 4 my $next = shift;
150 4 my ($self, @args) = @_;
151  
152 0 ▶ my %args = (@args == 1 && ref $args[0] eq 'HASH' ? %{ $args[0] } : @args);
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 && ref $args[0] eq 'HASH' ? : 0 4 4
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
400
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
153 my $class = $args{package}
154 4 ▶ or croak 'You need to specify a package in the constructor arguments';
Branch: 1 branch
BranchTrueFalseTotal
my $class = $args{"package"} or croak("You need to specify a package in the constructor arguments") 4 0 4
155  
156 4 load_class($class);
157 4 ▶ return Pod::Coverage->new(%args) unless $class->can('meta');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("meta") 1 3 4
158  
159 3 return $self->$next(@args);
160 3 };
161  
162 3 1;
163  
164 __END__
↑ Summary