Moose.pm

filter: Statementstmt 95.5% 128 / 134 Branchbran 80.5% 29 / 36 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 32 / 32 Podpod 66.6% 6 / 9 totaltotal 91.8% 203 / 221 CC 23 SCAR 11.2
CC
23
Cov
92%
import
7.0
test_methods
6.0
Tags
4.1
CRAP 3.1
« Moose/Role.pm ↑ Summary Moose/Role/CLI.pm »
1 package Test::Class::Moose;
2  
3 # ABSTRACT: Serious testing for serious Perl
4  
5 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 31 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 31 our $VERSION = '1.00';
12  
13 31 ▶use Moose 2.0000;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 31 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 31 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 31 ▶use Sub::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # We don't use anything from this module in this one, but we want to require a
19 # specific version.
20 31 ▶use Test2 1.302118 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 31 ▶use Test::Class::Moose::AttributeRegistry;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 31 ▶use Test::Class::Moose::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 31 ▶use Test::Class::Moose::Deprecated;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 33 ▶sub __sub_attr_declaration_code {
Subroutine __sub_attr_declaration_code: called CC=1 SCAR=0.0
27  
28 # XXX sharing this behavior here because my first attempt at creating a
29 # role was a complete failure. MooseX::MethodAttributes can help here, but
30 # I have to parse the attributes manually (as far as I can tell) and I
31 # don't have the simple declarative style any more.
32 33 return <<'DECLARE_ATTRIBUTES';
33 sub Tags : ATTR_SUB {
34 my ( $class, $symbol, undef, undef, $data, undef, $file, $line ) = @_;
35  
36 my @tags;
37 if ($data) {
38 $data =~ s/^\s+//g;
39 @tags = split /\s+/, $data;
40 }
41  
42 if ( $symbol eq 'ANON' ) {
43 die "Cannot tag anonymous subs at file $file, line $line\n";
44 }
45  
46 my $method = *{$symbol}{NAME};
47  
48 { # block for localising $@
49 local $@;
50  
51 Test::Class::Moose::AttributeRegistry->add_tags(
52 $class,
53 $method,
54 \@tags,
55 );
56 if ($@) {
57 croak "Error in adding tags: $@";
58 }
59 }
60 }
61  
62 sub Test : ATTR_SUB {
63 my ( $class, $symbol, undef, undef, undef, undef, $file, $line ) = @_;
64  
65 if ( $symbol eq 'ANON' ) {
66 croak("Cannot add plans to anonymous subs at file $file, line $line");
67 }
68  
69 my $method = *{$symbol}{NAME};
70 if ( $method =~ /^test_(?:startup|setup|teardown|shutdown)$/ ) {
71 croak("Test control method '$method' may not have a Test attribute");
72 }
73  
74 Test::Class::Moose::AttributeRegistry->add_plan(
75 $class,
76 $method,
77 1,
78 );
79 $class->meta->add_before_method_modifier($method, sub {
80 my $test = shift;
81 $test->test_report->plan(1);
82 });
83 }
84  
85 sub Tests : ATTR_SUB {
86 my ( $class, $symbol, undef, undef, $data, undef, $file, $line ) = @_;
87  
88 if ( $symbol eq 'ANON' ) {
89 croak("Cannot add plans to anonymous subs at file $file, line $line");
90 }
91  
92 my $method = *{$symbol}{NAME};
93 if ( $method =~ /^test_(?:startup|setup|teardown|shutdown)$/ ) {
94 croak("Test control method '$method' may not have a Test attribute");
95 }
96  
97 Test::Class::Moose::AttributeRegistry->add_plan(
98 $class,
99 $method,
100 $data,
101 );
102 if ( defined $data ) {
103 $class->meta->add_before_method_modifier($method, sub {
104 my $test = shift;
105 $test->test_report->plan($data);
106 });
107 }
108 }
109 DECLARE_ATTRIBUTES
110 }
111  
112 31 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
113 ## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
114 0 ▶ eval __PACKAGE__->__sub_attr_declaration_code;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine Tags: called CC=4 SCAR=14.0
Subroutine Test: called CC=3 SCAR=11.1
Subroutine Tests: called CC=4 SCAR=14.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Pod undocumented
Pod documented
Pod undocumented
Branch: 8 branches
BranchTrueFalseTotal
if ($data) 22 1 23
if ($symbol eq "ANON") 0 23 23
if ($@) 0 23 23
if ($symbol eq "ANON") 0 3 3
if ($method =~ /^test_(?:startup|setup|teardown|shutdown)$/) 1 2 3
if ($symbol eq "ANON") 0 6 6
if ($method =~ /^test_(?:startup|setup|teardown|shutdown)$/) 0 6 6
if (defined $data) 4 2 6
115 31 ▶ croak($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 31 31
116 }
117  
118 31 has 'test_report' => (
119 is => 'ro',
120 isa => 'Test::Class::Moose::Report',
121 );
122  
123 has 'test_class' => (
124 is => 'ro',
125 isa => 'Str',
126 init_arg => undef,
127 71 ▶ default => sub { ref $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
128 31 );
129  
130 31 has 'test_instance_name' => (
131 is => 'rw',
132 writer => '_set_test_instance_name',
133 isa => 'Str',
134 init_arg => undef,
135 );
136  
137 31 has 'test_skip' => (
138 is => 'rw',
139 isa => 'Str',
140 clearer => 'test_skip_clear',
141 );
142  
143 168 ▶sub import {
Subroutine import: called CC=7 SCAR=19.5
144 168 shift;
145 168 my %args = @_;
146  
147 168 my $caller = caller;
148  
149 168 my @imports = qw(
150 Moose
151 Sub::Attribute
152 strict
153 warnings
154 );
155  
156 168 ▶ unless ( $args{bare} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"bare"}) 24 144 168
157 24 require Test::Most;
158 24 push @imports, 'Test::Most';
159 }
160  
161 168 $_->import::into($caller) for @imports;
162  
163 168 ▶ if ( my $parent = ( delete $args{parent} || delete $args{extends} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = delete $args{'parent'} || delete $args{'extends'}) { } 35 133 168
Condition66%2/3
delete $args{'parent'} || delete $args{'extends'}
l!l&&r!l&&!r
035133
MC/DC50%1/2
delete $args{'parent'} || delete $args{'extends'}
delete $args{'parent'} delete $args{'extends'}
Truth table66%2/3
A || B
A= delete $args{'parent'}B= delete $args{'extends'}
ABresult
1X1
011
000
164 35 ▶ my @parents = 'ARRAY' eq ref $parent ? @$parent : $parent;
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq ref $parent ? : 1 34 35
165 35 $caller->meta->superclasses(@parents);
166 35 ▶ unless ( $caller->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($caller->isa(__PACKAGE__)) 3 32 35
167 3 croak( _bad_parents_error($caller) );
168 }
169 }
170 else {
171 133 $caller->meta->superclasses(__PACKAGE__);
172 }
173 }
174  
175 3 ▶sub _bad_parents_error {
Subroutine _bad_parents_error: called CC=3 SCAR=11.0
176 3 my $class = shift;
177  
178 3 my @ancestors = $class->meta->linearized_isa;
179  
180 # The first element is always $class
181 3 shift @ancestors;
182  
183 3 my $me = "The $class class";
184 3 ▶ if ( scalar @ancestors == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ancestors == 1) 2 1 3
185 2 return "$me inherits from $ancestors[0] which does not inherit from "
186 . __PACKAGE__;
187 }
188  
189 1 my $heritage;
190 1 ▶ if ( scalar @ancestors == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ancestors == 2) { } 0 1 1
191 0 $heritage .= join ' and ', @ancestors;
192 }
193 else {
194 1 my $final = pop @ancestors;
195 1 $heritage .= join ', ', @ancestors;
196 1 $heritage .= ", and $final";
197 }
198  
199 return
200 1 "$me has $heritage as ancestors "
201 . 'but none of these classes inherit from '
202 . __PACKAGE__;
203 }
204  
205 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
206 40 ▶sub _tcm_make_test_class_instances {
Subroutine _tcm_make_test_class_instances: called CC=1 SCAR=0.0
207 40 my $test_class = shift;
208  
209 40 my $instance = $test_class->new(@_);
210 40 $instance->_set_test_instance_name($test_class);
211  
212 40 return $instance;
213 }
214  
215 190 ▶sub test_methods {
Subroutine test_methods: called CC=6 SCAR=17.9
Pod documented
216 190 my $self = shift;
217  
218 190 my @method_list;
219 190 foreach my $method ( $self->meta->get_all_methods ) {
220  
221 # attributes cannot be test methods
222 7147 ▶ next if $method->isa('Moose::Meta::Method::Accessor');
Branch: 1 branch
BranchTrueFalseTotal
if $method->isa("Moose::Meta::Method::Accessor") 1267 5880 7147
223  
224 5880 my $class = ref $self;
225 5880 my $name = $method->name;
226 next
227 5880 ▶ unless $name =~ /^test_/
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^test_/ or "Test::Class::Moose::AttributeRegistry"->has_test_attribute($class, $name) 4380 1500 5880
Condition100%3/3
$name =~ /^test_/ or "Test::Class::Moose::AttributeRegistry"->has_test_attribute($class, $name)
l!l&&r!l&&!r
149824380
MC/DC100%2/2
$name =~ /^test_/ or "Test::Class::Moose::AttributeRegistry"->has_test_attribute($class, $name)
$name =~ /^test_/ "Test::Class::Moose::AttributeRegistry"->has_test_attribute($class, $name)
Truth table100%3/3
A or B
A= $name =~ /^test_/B= "Test::Class::Moose::AttributeRegistry"->has_test_attribute($class, $name)
ABresult
1X1
011
000
228 || Test::Class::Moose::AttributeRegistry->has_test_attribute(
229 $class, $name );
230  
231 # don't use anything defined in this package
232 1500 ▶ next if __PACKAGE__->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->can($name) 950 550 1500
233 550 push @method_list => $name;
234 }
235  
236 190 return @method_list;
237 }
238  
239 # empty stub methods guarantee that subclasses can always call these
240 38 ▶sub test_startup { }
Subroutine test_startup: called CC=1 SCAR=0.0
Pod documented
241 45 ▶sub test_setup { }
Subroutine test_setup: called CC=1 SCAR=0.0
Pod documented
242 102 ▶sub test_teardown { }
Subroutine test_teardown: called CC=1 SCAR=0.0
Pod documented
243 40 ▶sub test_shutdown { }
Subroutine test_shutdown: called CC=1 SCAR=0.0
Pod documented
244  
245 41 ▶sub run_control_methods_on_skip {0}
Subroutine run_control_methods_on_skip: called CC=1 SCAR=0.0
Pod undocumented
246  
247 31 __PACKAGE__->meta->make_immutable;
248  
249 31 1;
250  
251 __END__
« Moose/Role.pm ↑ Summary Moose/Role/CLI.pm »