Run/Base.pm

filter: Statementstmt 100% 73 / 73 Branchbran 100% 4 / 4 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 20 / 20 Podpod 100% 2 / 2 totaltotal 100% 105 / 105 CC 7 SCAR 3.8
CC
7
Cov
100%
copy_from
2.0
_format
2.0
_format_self
2.0
CRAP 1.5
« Run/Core.pm ↑ Summary Run/Obj/FailedObj.pm »
1 package Test::Run::Base;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 =head1 NAME
10  
11 Test::Run::Base - base class for all of Test::Run.
12  
13 =head1 DESCRIPTION
14  
15 This is the base class for all Test::Run classes. It inherits from
16 L<Class::Accessor> and provides some goodies of its own.
17  
18 =head1 METHODS
19  
20 =cut
21  
22 24 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 24 ▶use Text::Sprintf::Named;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 24 ▶use Test::Run::Sprintf::Named::FromAccessors;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 24 ▶use Test::Run::Class::Hierarchy (qw(hierarchy_of rev_hierarchy_of));
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 24 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1145 ▶has '_formatters' => (is => "rw", isa => "HashRef", default => sub { +{} },);
Subroutine __ANON__: called CC=1 SCAR=0.0
32  
33 =head2 $package->new({%args})
34  
35 The default constructor. Do not over-ride it. Instead, define a
36 L<BUILD()> method.
37  
38 =cut
39  
40 =head2 $dest->copy_from($source, [@fields])
41  
42 Assigns the fields C<@fields> using their accessors based on their values
43 in C<$source>.
44  
45 =cut
46  
47 sub copy_from
48 57 ▶{
Subroutine copy_from: called CC=2 SCAR=6.9
Pod documented
49 57 my ($dest, $source, $fields) = @_;
50  
51 57 foreach my $f (@$fields)
52 {
53 228 $dest->$f($source->$f());
54 }
55  
56 57 return;
57 }
58  
59 sub _get_formatter
60 476 ▶{
Subroutine _get_formatter: called CC=1 SCAR=0.0
61 476 my ($self, $fmt) = @_;
62  
63 return
64 476 Text::Sprintf::Named->new(
65 { fmt => $fmt, },
66 );
67 }
68  
69 sub _register_formatter
70 468 ▶{
Subroutine _register_formatter: called CC=1 SCAR=0.0
71 468 my ($self, $name, $fmt) = @_;
72  
73 468 $self->_formatters->{$name} = $self->_get_formatter($fmt);
74  
75 468 return;
76 }
77  
78 sub _get_obj_formatter
79 685 ▶{
Subroutine _get_obj_formatter: called CC=1 SCAR=0.0
80 685 my ($self, $fmt) = @_;
81  
82 return
83 685 Test::Run::Sprintf::Named::FromAccessors->new(
84 { fmt => $fmt, },
85 );
86 }
87  
88 sub _register_obj_formatter
89 671 ▶{
Subroutine _register_obj_formatter: called CC=1 SCAR=0.0
90 671 my ($self, $args) = @_;
91  
92 671 my $name = $args->{name};
93 671 my $fmt = $args->{format};
94  
95 671 $self->_formatters->{$name} = $self->_get_obj_formatter($fmt);
96  
97 671 return;
98 }
99  
100 sub _format
101 121 ▶{
Subroutine _format: called CC=2 SCAR=6.9
102 121 my ($self, $format, $args) = @_;
103  
104 121 ▶ if (ref($format) eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $format eq '') { } 113 8 121
105 {
106 113 return $self->_formatters->{$format}->format({ args => $args});
107 }
108 else
109 {
110 8 return $self->_get_formatter(${$format})->format({ args => $args});
111 }
112 }
113  
114 sub _format_self
115 43 ▶{
Subroutine _format_self: called CC=2 SCAR=6.9
116 43 my ($self, $format, $args) = @_;
117  
118 43 ▶ $args ||= {};
Condition100%2/2
$args ||= {}
l!l
142
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
119  
120 43 return $self->_format($format, { obj => $self, %{$args}});
121 }
122  
123 =head2 $self->accum_array({ method => $method_name })
124  
125 This is a more simplistic version of the :CUMULATIVE functionality
126 in Class::Std. It was done to make sure that one can collect all the
127 members of array refs out of methods defined in each class into one big
128 array ref, that can later be used.
129  
130 =cut
131  
132 sub accum_array
133 204 ▶{
Subroutine accum_array: called CC=2 SCAR=6.9
Pod documented
134 204 my ($self, $args) = @_;
135  
136 204 my $method_name = $args->{method};
137  
138 # my $class = ((ref($self) eq "") ? $self : ref($self));
139  
140 204 my @results;
141 204 foreach my $isa_class (
142 $self->meta->find_all_methods_by_name($method_name)
143 )
144 {
145 7 my $body = $isa_class->{code}->body();
146 7 push @results, @{ $self->$body() };
147 }
148  
149 204 return \@results;
150 }
151  
152 sub _list_pluralize
153 12 ▶{
Subroutine _list_pluralize: called CC=1 SCAR=0.0
154 12 my ($self, $noun, $list) = @_;
155  
156 12 return $self->_pluralize($noun, scalar(@$list));
157 }
158  
159 sub _pluralize
160 21 ▶{
Subroutine _pluralize: called CC=2 SCAR=6.9
161 21 my ($self, $noun, $count) = @_;
162  
163 21 ▶ return sprintf("%s%s",
Branch: 1 branch
BranchTrueFalseTotal
$count > 1 ? : 5 16 21
164 $noun,
165 (($count > 1) ? "s" : "")
166 );
167 }
168  
169 =head2 $self->_run_sequence(\@params)
170  
171 Runs the sequence of commands specified using
172 C<_calc__${calling_sub}__callbacks> while passing @params to
173 each one. Generates a list of all the callbacks return values.
174  
175 =cut
176  
177 sub _run_sequence
178 543 ▶{
Subroutine _run_sequence: called CC=2 SCAR=6.9
179 543 my $self = shift;
180 543 ▶ my $params = shift || [];
Condition100%2/2
shift() || []
l!l
63480
MC/DC100%1/1
shift() || []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
181  
182 543 my $sub = (caller(1))[3];
183  
184 543 $sub =~ s{::_?([^:]+)$}{};
185  
186 543 my $calc_cbs_sub = "_calc__${1}__callbacks";
187  
188 return
189 [
190 1740 map { my $cb = $_; $self->$cb(@$params); }
191 543 @{$self->$calc_cbs_sub(@$params)}
192 ];
193 }
194  
195 24 1;
196  
197 __END__
« Run/Core.pm ↑ Summary Run/Obj/FailedObj.pm »