Ask/Question.pm

filter: Statementstmt 60.3% 102 / 169 Branchbran 37.0% 40 / 108 Conditioncond 21.1% 15 / 71 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 73.3% 11 / 15 Podpod 33.3% 1 / 3 totaltotal 41.3% 169 / 409 CC 79 SCAR 60.9
CC
79
Cov
45%
__ANON__
742.2
__ANON__
58.7
isa
30.0
CRAP 442.6
↑ Summary Ask/Caroline.pm »
1 1 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Ask::Question;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.015';
9  
10 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶ '&{}' => sub { shift->coderef },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 1 fallback => 1,
16 1 );
17  
18 0 ▶sub ask { shift->coderef->() }
Subroutine ask: not called CC=1 SCAR=6.9
Pod documented
19  
20 1 has backend => ( is => 'lazy' );
21 1 has type => ( is => 'rwp', predicate => 1 );
22 1 has spec => ( is => 'rwp', predicate => 1 );
23 1 has title => ( is => 'rwp', predicate => 1 );
24 1 has text => ( is => 'rwp', predicate => 1 );
25 1 has multiple => ( is => 'rwp' );
26 1 has choices => ( is => 'rwp' );
27 1 has coderef => ( is => 'lazy', init_arg => undef );
28 1 has default => ( is => 'rwp', predicate => 1 );
29 1 has method => ( is => 'rwp' );
30  
31 0 ▶sub _build_backend {
Subroutine _build_backend: not called CC=1 SCAR=6.9
32 0 require Ask;
33 0 'Ask'->instance;
34 }
35  
36 1 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=4 SCAR=15.6
Pod undocumented
37 1 my ( $class, @args ) = ( shift, @_ );
38 1 ▶ @args == 1 and ref $args[0] and return $args[0];
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 and ref $args[0] and return $args[0] 0 1 1
Condition33%1/3
@args == 1 and ref $args[0]
!ll&&!rl&&r
100
MC/DC0%0/2
@args == 1 and ref $args[0]
@args == 1 ref $args[0]
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0]
ABresult
0X0
100
111
39 1 ▶ unshift @args, 'text' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 1 0 1
40 1 +{@args};
41 }
42  
43 0 ▶sub isa { # trick Moose
Subroutine isa: not called CC=5 SCAR=34.0
Pod undocumented
44 0 ▶ return 1 if $_[1] eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq __PACKAGE__ 0 0 0
45 0 ▶ return 1 if $_[1] eq 'Class::MOP::Method';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq "Class::MOP::Method" 0 0 0
46 0 ▶ return 1 if $_[1] eq 'Moo::Object';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq "Moo::Object" 0 0 0
47 0 ▶ return 1 if $_[1] eq 'UNIVERSAL';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq "UNIVERSAL" 0 0 0
48 0 return 0;
49 }
50  
51 1 ▶sub _build_coderef {
Subroutine _build_coderef: called CC=6 SCAR=25.9
52 1 my ( $self ) = ( shift );
53
54 # Avoid closing over $self
55 1 my $ask = $self->backend;
56 1 my $type = $self->type;
57 1 my $choices = $self->choices;
58 1 my $multiple = $self->multiple;
59 1 ▶ my $spec = $self->spec || {};
Condition50%1/2
$self->spec || {}
l!l
01
MC/DC0%0/1
$self->spec || {}
$self->spec
Truth table50%1/2
A
A= $self->spec
Aresult
11
00
60 1 ▶ my $default = $self->has_default ? $self->default : $spec->{default};
Branch: 1 branch
BranchTrueFalseTotal
$self->has_default ? : 0 1 1
61 1 ▶ my $text = $self->has_text ? $self->text : $spec->{documentation};
Branch: 1 branch
BranchTrueFalseTotal
$self->has_text ? : 1 0 1
62 1 my $method = $self->method;
63 1 my $title = $self->title;
64
65 1 ▶ undef $default if ( blessed $default and $default == $self );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($default) and $default == $self 0 1 1
Condition33%1/3
builtin::blessed($default) and $default == $self
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($default) and $default == $self
builtin::blessed($default) $default == $self
Truth table33%1/3
A and B
A= builtin::blessed($default)B= $default == $self
ABresult
0X0
100
111
66
67 1 ▶ return sub {
Subroutine __ANON__: called CC=54 SCAR=66.1
68 1 my @args = @_;
69 1 my ( $instance ) = ( @args );
70
71 1 my $local_text = $text;
72 1 ▶ if ( ref $local_text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $local_text) 0 1 1
73 0 $local_text = $local_text->( @args );
74 }
75 1 ▶ if ( not defined $local_text ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $local_text) 0 1 1
76 0 $local_text = '?';
77 }
78
79 1 my $local_default = $default;
80 1 ▶ if ( ref $local_default ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $local_default) 0 1 1
81 0 $local_default = $local_default->( @args );
82 }
83
84 1 ▶ unless ( blessed($ask) and $ask->DOES('Ask::API') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($ask) and $ask->DOES("Ask::API")) 0 1 1
Condition33%1/3
builtin::blessed($ask) and $ask->DOES("Ask::API")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($ask) and $ask->DOES("Ask::API")
builtin::blessed($ask) $ask->DOES("Ask::API")
Truth table33%1/3
A and B
A= builtin::blessed($ask)B= $ask->DOES("Ask::API")
ABresult
0X0
100
111
85 0 $ask = $ask->();
86 }
87
88 1 my $local_type = $type;
89 1 ▶ if ( not ref $local_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $local_type) 0 1 1
90
91 0 ▶ $local_type ||= $spec->{type};
Condition0%0/3
$local_type ||= $spec->{"type"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$local_type ||= $spec->{"type"}
$local_type $spec->{"type"}
Truth table0%0/3
A ||= B
A= $local_typeB= $spec->{"type"}
ABresult
1X1
011
000
92
93 0 ▶ if ( defined $local_type and not ref $local_type ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $local_type and not ref $local_type) { } 0 0 0
elsif (defined $spec->{'isa'} and not ref $local_type) { } 0 0 0
elsif (defined $spec->{'does'} and not ref $local_type) { } 0 0 0
Condition0%0/3
defined $local_type and not ref $local_type
!ll&&!rl&&r
000
MC/DC0%0/2
defined $local_type and not ref $local_type
defined $local_type not ref $local_type
Truth table0%0/3
A and not(B)
A= defined $local_typeB= not ref $local_type
ABresult
0X0
100
111
94 0 require Type::Utils;
95 0 $local_type = Type::Utils::dwim_type(
96 $local_type,
97 for => ref( $instance ),
98 );
99 }
100
101 ▶ elsif ( defined $spec->{'isa'} and not ref $local_type ) {
Condition0%0/3
defined $spec->{"isa"} and not ref $local_type
!ll&&!rl&&r
000
MC/DC0%0/2
defined $spec->{"isa"} and not ref $local_type
defined $spec->{"isa"} not ref $local_type
Truth table0%0/3
A and not(B)
A= defined $spec->{"isa"}B= not ref $local_type
ABresult
0X0
100
111
102 $local_type =
103 ref( $spec->{'isa'} )
104 ? $spec->{'isa'}
105 0 ▶ : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $spec->{'isa'} ? : 0 0 0
106 0 require Type::Utils;
107 Type::Utils::dwim_type(
108 0 $spec->{'isa'},
109 for => ref( $instance ),
110 fallback => ['make_class_type'],
111 );
112 };
113 } #/ elsif ( defined $spec->{'isa'...})
114
115 ▶ elsif ( defined $spec->{'does'} and not ref $local_type ) {
Condition0%0/3
defined $spec->{"does"} and not ref $local_type
!ll&&!rl&&r
000
MC/DC0%0/2
defined $spec->{"does"} and not ref $local_type
defined $spec->{"does"} not ref $local_type
Truth table0%0/3
A and not(B)
A= defined $spec->{"does"}B= not ref $local_type
ABresult
0X0
100
111
116 $local_type =
117 ref( $spec->{'does'} )
118 ? $spec->{'does'}
119 0 ▶ : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $spec->{'does'} ? : 0 0 0
120 0 require Type::Utils;
121 Type::Utils::dwim_type(
122 0 $spec->{'does'},
123 for => ref( $instance ),
124 fallback => ['make_role_type'],
125 );
126 };
127 } #/ elsif ( defined $spec->{'does'...})
128 } #/ if ( not ref $local_type)
129
130 1 my $local_multiple = $multiple;
131 1 ▶ if ( blessed $local_type and not defined $local_multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($local_type) and not defined $local_multiple) 1 0 1
Condition33%1/3
builtin::blessed($local_type) and not defined $local_multiple
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($local_type) and not defined $local_multiple
builtin::blessed($local_type) not defined $local_multiple
Truth table33%1/3
A and not(B)
A= builtin::blessed($local_type)B= not defined $local_multiple
ABresult
0X0
100
111
132 1 require Types::Standard;
133 1 $local_multiple = ( $local_type <= Types::Standard::ArrayRef() );
134 }
135
136 1 my $local_choices = $choices;
137 1 ▶ if ( defined $local_type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $local_type and builtin::blessed($local_type) and not defined $local_choices) 1 0 1
Condition33%2/6
defined $local_type and builtin::blessed($local_type) and not defined $local_choices
!ll&&!rl&&r
001
defined $local_type and builtin::blessed($local_type)
!ll&&!rl&&r
001
MC/DC0%0/3
defined $local_type and builtin::blessed($local_type) and not defined $local_choices
defined $local_type builtin::blessed($local_type) not defined $local_choices
Truth table25%1/4
A and B and not(C)
A= defined $local_typeB= builtin::blessed($local_type)C= not defined $local_choices
ABCresult
0XX0
10X0
1100
1111
138 and blessed $local_type
139 and not defined $local_choices )
140 {
141 0 ▶ my $map = sub { [ map [ $_ x 2 ], @{ +shift } ] };
Subroutine __ANON__: not called CC=1 SCAR=2.6
142 1 require Types::Standard;
143 1 ▶ if ( $local_type->isa( 'Type::Tiny::Enum' ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($local_type->isa('Type::Tiny::Enum')) { } 0 1 1
elsif ($local_type->isa('Moose::Meta::TypeConstraint::Enum')) { } 0 1 1
elsif ($local_type <= &Types::Standard::ArrayRef() and $local_type->is_parameterized) { } 1 0 1
144 0 $local_choices = $map->( $local_type->unique_values );
145 }
146 elsif ( $local_type->isa( 'Moose::Meta::TypeConstraint::Enum' ) ) {
147 0 $local_choices = $map->( $local_type->values );
148 }
149 ▶ elsif ( $local_type <= Types::Standard::ArrayRef()
Condition33%1/3
$local_type <= &Types::Standard::ArrayRef() and $local_type->is_parameterized
!ll&&!rl&&r
001
MC/DC0%0/2
$local_type <= &Types::Standard::ArrayRef() and $local_type->is_parameterized
$local_type <= &Types::Standard::ArrayRef() $local_type->is_parameterized
Truth table33%1/3
A and B
A= $local_type <= &Types::Standard::ArrayRef()B= $local_type->is_parameterized
ABresult
0X0
100
111
150 and $local_type->is_parameterized )
151 {
152 1 my $tp = $local_type->type_parameter;
153 1 ▶ if ( $tp->isa( 'Type::Tiny::Enum' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tp->isa('Type::Tiny::Enum')) { } 0 1 1
elsif ($tp->isa('Moose::Meta::TypeConstraint::Enum')) { } 0 1 1
154 0 $local_choices = $map->( $tp->unique_values );
155 }
156 elsif ( $tp->isa( 'Moose::Meta::TypeConstraint::Enum' ) ) {
157 0 $local_choices = $map->( $tp->values );
158 }
159 } #/ elsif ( $local_type <= Types::Standard::ArrayRef...)
160 } #/ if ( defined $local_type...)
161
162 1 my $is_bool;
163 1 ▶ if ( defined $local_type and blessed $local_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $local_type and builtin::blessed($local_type)) 1 0 1
Condition33%1/3
defined $local_type and builtin::blessed($local_type)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $local_type and builtin::blessed($local_type)
defined $local_type builtin::blessed($local_type)
Truth table33%1/3
A and B
A= defined $local_typeB= builtin::blessed($local_type)
ABresult
0X0
100
111
164 1 require Types::Standard;
165 1 $is_bool = !!( $local_type <= Types::Standard::Bool() );
166 }
167
168 1 my ( $is_path, $is_dir, $is_abs );
169 1 ▶ if ( defined $local_type and blessed $local_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $local_type and builtin::blessed($local_type)) 1 0 1
Condition33%1/3
defined $local_type and builtin::blessed($local_type)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $local_type and builtin::blessed($local_type)
defined $local_type builtin::blessed($local_type)
Truth table33%1/3
A and B
A= defined $local_typeB= builtin::blessed($local_type)
ABresult
0X0
100
111
170
171 1 ▶ if ( eval { require Types::Path::Tiny } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Types::Path::Tiny } }) 0 1 1
172 0 $is_path = !!( $local_type <= Types::Path::Tiny::Path() );
173 0 ▶ my $path_type = $is_path ? $local_type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$is_path ? : 0 0 0
174
175 0 require Types::Standard;
176 0 ▶ if ( !$is_path
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_path and $local_type <= &Types::Standard::ArrayRef() and $local_type->is_parameterized) 0 0 0
Condition0%0/6
not $is_path and $local_type <= &Types::Standard::ArrayRef() and $local_type->is_parameterized
!ll&&!rl&&r
000
not $is_path and $local_type <= &Types::Standard::ArrayRef()
!ll&&!rl&&r
000
MC/DC0%0/3
not $is_path and $local_type <= &Types::Standard::ArrayRef() and $local_type->is_parameterized
not $is_path $local_type <= &Types::Standard::ArrayRef() $local_type->is_parameterized
Truth table0%0/4
not(A) and B and C
A= not $is_pathB= $local_type <= &Types::Standard::ArrayRef()C= $local_type->is_parameterized
ABCresult
0XX0
10X0
1100
1111
177 and $local_type <= Types::Standard::ArrayRef()
178 and $local_type->is_parameterized )
179 {
180 0 my $tp = $local_type->type_parameter;
181 0 ▶ if ( $tp <= Types::Path::Tiny::Path() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tp <= Types::Path::Tiny::Path()) 0 0 0
182 0 $is_path = 1;
183 0 $local_multiple = 1;
184 0 $path_type = $tp;
185 }
186 } #/ if ( !$is_path and $local_type...)
187
188 0 ▶ if ( $is_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_path) 0 0 0
189 0 ▶ $is_dir = ( $path_type <= Types::Path::Tiny::Dir() )
Condition0%0/3
$path_type <= Types::Path::Tiny::Dir() || $path_type <= Types::Path::Tiny::AbsDir()
l!l&&r!l&&!r
000
MC/DC0%0/2
$path_type <= Types::Path::Tiny::Dir() || $path_type <= Types::Path::Tiny::AbsDir()
$path_type <= Types::Path::Tiny::Dir() $path_type <= Types::Path::Tiny::AbsDir()
Truth table0%0/3
A || B
A= $path_type <= Types::Path::Tiny::Dir()B= $path_type <= Types::Path::Tiny::AbsDir()
ABresult
1X1
011
000
190 || ( $path_type <= Types::Path::Tiny::AbsDir() );
191 0 ▶ $is_abs =
Condition0%0/6
$path_type <= Types::Path::Tiny::AbsPath() || $path_type <= Types::Path::Tiny::AbsFile() || $path_type <= Types::Path::Tiny::AbsDir()
l!l&&r!l&&!r
000
$path_type <= Types::Path::Tiny::AbsPath() or $path_type <= Types::Path::Tiny::AbsFile()
l!l&&r!l&&!r
000
MC/DC0%0/3
$path_type <= Types::Path::Tiny::AbsPath() || $path_type <= Types::Path::Tiny::AbsFile() || $path_type <= Types::Path::Tiny::AbsDir()
$path_type <= Types::Path::Tiny::AbsPath() $path_type <= Types::Path::Tiny::AbsFile() $path_type <= Types::Path::Tiny::AbsDir()
Truth table0%0/4
A or B || C
A= $path_type <= Types::Path::Tiny::AbsPath()B= $path_type <= Types::Path::Tiny::AbsFile()C= $path_type <= Types::Path::Tiny::AbsDir()
ABCresult
1XX1
01X1
0011
0000
192 ( $path_type <= Types::Path::Tiny::AbsPath() )
193 || ( $path_type <= Types::Path::Tiny::AbsFile() )
194 || ( $path_type <= Types::Path::Tiny::AbsDir() );
195 }
196 } #/ if ( eval { require Types::Path::Tiny...})
197 } #/ if ( defined $local_type...)
198
199 1 ▶ my @common = (
Branch: 2 branches
BranchTrueFalseTotal
defined $title ? : 0 1 1
defined $local_default ? : 0 1 1
200 text => $local_text,
201 defined( $title ) ? ( title => $title ) : (),
202 defined( $local_default ) ? ( default => $local_default ) : (),
203 );
204
205 2 ▶ my $get_answer = sub {
Subroutine __ANON__: called CC=14 SCAR=40.7
206
207 2 ▶ if ( $method ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($method) { } 0 2 2
elsif ($local_multiple and $local_choices) { } 0 2 2
elsif ($local_choices) { } 0 2 2
elsif ($local_multiple and $is_path) { } 0 2 2
elsif ($is_path) { } 0 2 2
elsif ($is_bool) { } 0 2 2
elsif ($local_multiple) { } 2 0 2
208 0 my $str = $ask->$method(
209 choices => $choices,
210 multiple => $multiple,
211 @common,
212 );
213 0 chomp $str;
214 0 return $str;
215 }
216
217 ▶ elsif ( $local_multiple and $local_choices ) {
Condition33%1/3
$local_multiple and $local_choices
!ll&&!rl&&r
020
MC/DC0%0/2
$local_multiple and $local_choices
$local_multiple $local_choices
Truth table33%1/3
A and B
A= $local_multipleB= $local_choices
ABresult
0X0
100
111
218 0 my @values = $ask->multiple_choice( @common, choices => $local_choices );
219 0 return \@values;
220 }
221
222 elsif ( $local_choices ) {
223 0 return $ask->single_choice( @common, choices => $local_choices );
224 }
225
226 ▶ elsif ( $local_multiple and $is_path ) {
Condition33%1/3
$local_multiple and $is_path
!ll&&!rl&&r
020
MC/DC0%0/2
$local_multiple and $is_path
$local_multiple $is_path
Truth table33%1/3
A and B
A= $local_multipleB= $is_path
ABresult
0X0
100
111
227 0 require Path::Tiny;
228 0 my @paths = map( 'Path::Tiny'->new( $_ ),
229 $ask->file_selection( @common, directory => $is_dir, multiple => 1 ),
230 );
231 0 ▶ if ( $is_abs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_abs) 0 0 0
232 0 @paths = map $_->absolute, @paths;
233 }
234 0 return \@paths;
235 } #/ elsif ( $local_multiple and...)
236
237 elsif ( $is_path ) {
238 0 require Path::Tiny;
239 0 my $path = 'Path::Tiny'->new(
240 $ask->file_selection( @common, directory => $is_dir, multiple => 0 ),
241 );
242 0 ▶ return $is_abs ? $path->absolute : $path;
Branch: 1 branch
BranchTrueFalseTotal
$is_abs ? : 0 0 0
243 }
244
245 elsif ( $is_bool ) {
246 0 return $ask->question( @common, ok_label => 'TRUE', cancel_label => 'FALSE' );
247 }
248
249 elsif ( $local_multiple ) {
250 2 my @strings;
251 2 STRING: while ( 1 ) {
252 6 chomp( my $str = $ask->entry( @common ) );
253 6 ▶ if ( length $str ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) { } 4 2 6
254 4 push @strings, $str;
255 }
256 else {
257 2 last STRING;
258 }
259 4 ▶ return if @strings >= 100;
Branch: 1 branch
BranchTrueFalseTotal
if @strings >= 100 0 4 4
260 } #/ STRING: while ( 1 )
261 2 return \@strings;
262 } #/ elsif ( $local_multiple )
263
264 else {
265 0 chomp( my $str = $ask->entry( @common ) );
266 0 return $str;
267 }
268
269 1 }; # sub $get_answer
270
271 1 my $answer;
272 1 my $tries = 0;
273 1 ▶ TRY: while ( !defined $answer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $answer) 2 1 3
274
275 2 $answer = $get_answer->();
276 2 ++$tries;
277
278 2 ▶ if ( blessed $local_type ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($local_type)) { } 2 0 2
elsif (ref $local_type) { } 0 0 0
279 2 my $okay = $local_type->check( $answer );
280
281 2 ▶ if ( !$okay
Branch: 1 branch
BranchTrueFalseTotal
if (not $okay and $local_type->can("has_coercion") and $local_type->has_coercion) 2 0 2
Condition33%2/6
not $okay and $local_type->can("has_coercion") and $local_type->has_coercion
!ll&&!rl&&r
002
not $okay and $local_type->can("has_coercion")
!ll&&!rl&&r
002
MC/DC0%0/3
not $okay and $local_type->can("has_coercion") and $local_type->has_coercion
not $okay $local_type->can("has_coercion") $local_type->has_coercion
Truth table25%1/4
not(A) and B and C
A= not $okayB= $local_type->can("has_coercion")C= $local_type->has_coercion
ABCresult
0XX0
10X0
1100
1111
282 and $local_type->can( 'has_coercion' )
283 and $local_type->has_coercion )
284 {
285 2 $answer = $local_type->coerce( $answer );
286 2 $okay = $local_type->check( $answer );
287 }
288
289 2 ▶ if ( not $okay ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($okay) 1 1 2
290 1 $ask->error( text => $local_type->get_message( $answer ) );
291 1 $answer = undef;
292 }
293 } #/ if ( blessed $local_type)
294
295 elsif ( ref $local_type ) {
296 0 local $@;
297 0 my $okay = eval { $local_type->( $answer ); 1 };
298 0 ▶ if ( not $okay ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($okay) 0 0 0
299 0 $ask->error( text => $@ );
300 0 $answer = undef;
301 }
302 }
303
304 2 ▶ if ( $tries >= 3 and not defined $answer ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tries >= 3 and not defined $answer) 0 2 2
Condition33%1/3
$tries >= 3 and not defined $answer
!ll&&!rl&&r
200
MC/DC0%0/2
$tries >= 3 and not defined $answer
$tries >= 3 not defined $answer
Truth table33%1/3
A and not(B)
A= $tries >= 3B= not defined $answer
ABresult
0X0
100
111
305 0 $ask->error( text => 'Too many retries!' );
306 0 last TRY;
307 }
308 } #/ TRY: while ( !defined $answer )
309
310 1 ▶ return $answer if defined $answer;
Branch: 1 branch
BranchTrueFalseTotal
if defined $answer 1 0 1
311 0 return $local_default;
312 1 }; # built sub
313 } #/ sub _build_coderef
314  
315 1 1;
316  
317 __END__
↑ Summary Ask/Caroline.pm »