Fallback/Tiny.pm

filter: Statementstmt 27.6% 44 / 159 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 49 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 53.8% 14 / 26 Podpod n/a totaltotal 17.0% 58 / 341 CC 66 SCAR 57.0
CC
66
Cov
15%
_fallback
499.7
_normalize_fallback_opts
420.0
_smart_lookup
380.0
CRAP 299.0
↑ Summary Fallback/Moo.pm »
1 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Banal::Role::Fallback::Tiny;
7 # vim: set ts=2 sts=2 sw=2 tw=115 et :
8 # ABSTRACT: A tiny role that provides a 'fallback' method which helps building default values for object attributes.
9 # KEYWORDS: author utility
10  
11 1 our $VERSION = '0.001';
12 # AUTHORITY
13  
14 1 ▶use Banal::Util::Mini qw(tidy_arrayify hash_lookup_staged sanitize_subroutine_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Array::Utils qw(intersect);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Scalar::Util qw(blessed refaddr reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use List::Util 1.45 qw(any none pairs uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use List::MoreUtils qw(arrayify firstres listcmp);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Text::ParseWords qw(quotewords);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 requires qw( _fallback_settings );
25  
26  
27  
28 #######################################
29 0 ▶sub _resolve { # Transitional. Helps support an older name & interface to _fallback
Subroutine _resolve: not called CC=2 SCAR=17.9
30 #######################################
31 0 my $o = shift;
32 0 ▶ my %opt = %{ ref $_[0] eq 'HASH' ? shift : +{} };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
33 0 _fallback($o, { args_are_keys => 1, %opt}, @_)
34 }
35  
36 #######################################
37 0 ▶sub _resolve_mv { # Explicitely asks for an ARRAY reference.
Subroutine _resolve_mv: not called CC=2 SCAR=17.9
38 #######################################
39 # Also handles 'implicit additions' (extras that are appended systematically)
40 0 my $self = shift;
41 0 ▶ my $opt = ( ref ($_[0]) =~ /HASH/ ) ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref($_[0]) =~ /HASH/u ? : 0 0 0
42 0 $self->_resolve( { %$opt, want_reftype => 'ARRAY', multivalue => 1 }, @_);
43 }
44  
45 #######################################
46 0 ▶sub _resolve_mv_list { # Always returns a list, instead of an ARRAY reference.
Subroutine _resolve_mv_list: not called CC=1 SCAR=6.9
47 #######################################
48 0 @{ shift->_resolve_mv(@_) }
49 }
50  
51 #######################################
52 0 ▶sub _resolve_href { # Explicitely asks for a hash reference
Subroutine _resolve_href: not called CC=2 SCAR=17.9
53 #######################################
54 0 my $self = shift;
55 0 ▶ my $opt = ( ref ($_[0]) =~ /HASH/ ) ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref($_[0]) =~ /HASH/u ? : 0 0 0
56 0 $self->_resolve( { %$opt, want_reftype => 'HASH' }, @_ );
57 }
58  
59  
60 # Practical method-helper for determining the effective value to be used for a given attribute for a given object.
61 # The object would need to satisfy several conditions, though
62 #######################################
63 0 ▶sub _fallback {
Subroutine _fallback: not called CC=23 SCAR=62.1
64 #######################################
65 0 local $_;
66 0 my ($o, %opt) = &_normalize_fallback_opts;
67 0 my @keys = tidy_arrayify( $opt{keys} );
68 0 my @blankers = tidy_arrayify( $opt{blanker_token} );
69 0 my @mid = tidy_arrayify( @opt{qw( via )});
70 0 ▶ @mid = tidy_arrayify( @opt{qw( mid nrm normally )}, \&_smart_lookup) unless !!@mid;
Branch: 1 branch
BranchTrueFalseTotal
if not @mid 0 0 0
71 my @attempts = tidy_arrayify(
72 @opt{qw( apriori primo )},
73 @mid,
74 0 @opt{qw( def last fin final finally )}
75 );
76 0 my @res;
77 0 my $debug = $opt{debug};
78  
79 # say STDERR "Looking up keys : " . np @keys if $debug;
80 ATTEMPT:
81 0 foreach my $item (@attempts) {
82 0 ▶ next unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 0 0
83 my $v = (reftype($item) // '') eq 'CODE'
84 0 ▶ ? eval { $item->($o, \%opt) }
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($item) // '') eq 'CODE' ? : 0 0 0
Condition0%0/2
builtin::reftype($item) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($item) // ""
builtin::reftype($item)
Truth table0%0/2
A
A= builtin::reftype($item)
Aresult
11
00
85 : $item;
86  
87 # say STDERR "Attempt died on us : $@" if $@ && $debug;
88  
89 0 ▶ if (defined($v) && !$@) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and not $@) 0 0 0
Condition0%0/3
defined $v and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not $@
defined $v not $@
Truth table0%0/3
A and not(B)
A= defined $vB= not $@
ABresult
0X0
100
111
90 0 push @res, $v;
91 0 last ATTEMPT;
92 }
93 0 eval {; 1 }; # clear the last error
94 }
95  
96 0 @res = tidy_arrayify(@res);
97  
98 # say STDERR " Got (raw) : " . np @res if $debug;
99  
100 {
101 0 ▶ no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.2
102 0 my @greps = tidy_arrayify( $opt{grep}, $opt{greps});
103 0 ▶ push @greps, sub {; my @v=($_); !intersect(@blankers, @v) } if (@blankers);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if @blankers 0 0 0
104  
105 0 foreach my $f ( @greps ) {
106 0 ▶ my $rt = reftype($f) // '';
Condition0%0/2
builtin::reftype($f) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($f) // ""
builtin::reftype($f)
Truth table0%0/2
A
A= builtin::reftype($f)
Aresult
11
00
107 @res = grep {
108 0 my $gr = $_;
109 0 ▶ $rt eq 'CODE' and $gr = $f->($_);
Branch: 1 branch
BranchTrueFalseTotal
$rt eq "CODE" and $gr = &$f($_) 0 0 0
110 0 ▶ $rt eq 'REGEXP' and $gr = m/$f/;
Branch: 1 branch
BranchTrueFalseTotal
$rt eq "REGEXP" and $gr = /$f/u 0 0 0
111 0 ▶ !$rt and $gr = looks_like_number($f) ? ($_ == $f) : ($_ eq "$f");
Branch: 2 branches
BranchTrueFalseTotal
$rt or $gr = looks_like_number($f) ? $_ == $f : $_ eq "$f" 0 0 0
looks_like_number($f) ? : 0 0 0
112 0 $gr
113 }@res;
114 }
115 0 ▶ @res = uniq(@res) unless $opt{no_uniq} && !$opt{uniq};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"no_uniq"} and not $opt{"uniq"} 0 0 0
Condition0%0/3
$opt{"no_uniq"} and not $opt{"uniq"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opt{"no_uniq"} and not $opt{"uniq"}
$opt{"no_uniq"} not $opt{"uniq"}
Truth table0%0/3
A and not(B)
A= $opt{"no_uniq"}B= not $opt{"uniq"}
ABresult
0X0
100
111
116 0 ▶ @res = sort @res if $opt{sort};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"sort"} 0 0 0
117 }
118  
119 # say STDERR " Keys : " . np @keys if grep { m/install/ } @keys;
120 # say STDERR " Got : " . np @res if $debug;
121  
122 0 ▶ return [ @res ] if $opt{want_reftype} eq 'ARRAY' ;
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"want_reftype"} eq "ARRAY" 0 0 0
123 0 ▶ return unless @res; # Got no results at all. Signal that.
Branch: 1 branch
BranchTrueFalseTotal
unless @res 0 0 0
124 0 ▶ return $res[0] if @res == 1; # If we've got only one value, then there is no ambiguity. Just return that.
Branch: 1 branch
BranchTrueFalseTotal
if @res == 1 0 0 0
125  
126 0 ▶ if ( $opt{want_reftype} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"want_reftype"} eq "HASH") 0 0 0
127 0 ▶ my %res = map {; ref ($_) =~ /HASH/ix ? ( %{$_} ) : () } reverse @res; # effectively shallow-merge the resulting hashes
Branch: 1 branch
BranchTrueFalseTotal
ref($_) =~ /HASH/iux ? : 0 0 0
128 0 return +{ %res };
129 }
130  
131 # At this stage, even if we have more than one value, we only return the first found.
132 # CONSIDER: raising an error, perhaps.
133 0 return $res[0];
134 }
135  
136 #
137 # #######################################
138 # around _fallback => sub { # DEBUG wrapper.
139 # #######################################
140 # my $orig = shift;
141 # my ($o, %opt) = &_normalize_fallback_opts;
142 # my @keys = tidy_arrayify( $opt{keys} );
143 # my $debug = $opt{debug};
144 # my %info = (keys => [@keys] );
145 #
146 # if (wantarray) {
147 # say STDERR "\n\nFallback in ARRAY context for keys [@keys] ... " if $debug;
148 # my @r = $o->$orig($o, \%opt, @_);
149 # $info{result} = [@r];
150 # say STDERR "Fallback in ARRAY context. info : " . np %info if $debug;
151 # return @r;
152 # } else {
153 # say STDERR "\n\nFallback in SCALAR context for keys [@keys] ... " if $debug;
154 # my $r = scalar($o->$orig($o, \%opt, @_));
155 # $info{result} = $r;
156 # say STDERR " Fallback result in SCALAR context. info : " . np %info if $debug;
157 # return $r;
158 # }
159 #
160 # };
161 #
162  
163 #######################################
164 0 ▶sub _smart_lookup {
Subroutine _smart_lookup: not called CC=19 SCAR=59.4
165 #######################################
166 # Returns the first found item (corresponding to any of the given keys) in any of the hash sources.
167 0 local $_;
168 0 my ($o, %opt) = &_normalize_fallback_opts;
169 my @keys = tidy_arrayify( $opt{keys} )
170 0 ▶ or die "No keys given for us to lookup during staged fallback!";
Branch: 1 branch
BranchTrueFalseTotal
my(@keys) = &tidy_arrayify($opt{"keys"}) or die "No keys given for us to lookup during staged fallback!" 0 0 0
171 0 my @res;
172 0 ▶ my @sfx = tidy_arrayify( $opt{implicit_suffix} // '_implicit' );
Condition0%0/2
$opt{"implicit_suffix"} // "_implicit"
l!l
00
MC/DC0%0/1
$opt{"implicit_suffix"} // "_implicit"
$opt{"implicit_suffix"}
Truth table0%0/2
A
A= $opt{"implicit_suffix"}
Aresult
11
00
173 0 my @blankers = tidy_arrayify( $opt{blanker_token} );
174 0 my @no_implicit = tidy_arrayify( $opt{no_implicit} );
175 0 my $debug = $opt{debug};
176  
177 0 ▶ push @no_implicit, sub {; shift; shift; intersect(@blankers, @_) } if (@blankers);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if @blankers 0 0 0
178  
179 # say STDERR " Smart-lookup keys : " . np @keys if $debug;
180  
181 SUFFIX:
182 0 foreach my $suffix ('', @sfx) {
183 0 ▶ if ($suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) 0 0 0
184 # An non-empty suffix means we are dealing with an 'implcit' lookup.
185 0 ▶ last if any { ( reftype($_) eq 'CODE') ? $_->($o, \%opt, @res) : $_ } @no_implicit;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { builtin::reftype($_) eq "CODE" ? &$_($o, \%opt, @res) : $_; } , @no_implicit) 0 0 0
builtin::reftype($_) eq 'CODE' ? : 0 0 0
186 }
187  
188 0 my @mkeys = map {; $_ . $suffix } @keys;
189 0 my $found;
190  
191 # Try $o->$key_$suffix(...)
192 0 ▶ if ( $suffix && !$opt{no_implicit_accessor_calls} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix and not $opt{"no_implicit_accessor_calls"}) 0 0 0
Condition0%0/3
$suffix and not $opt{"no_implicit_accessor_calls"}
!ll&&!rl&&r
000
MC/DC0%0/2
$suffix and not $opt{"no_implicit_accessor_calls"}
$suffix not $opt{"no_implicit_accessor_calls"}
Truth table0%0/3
A and not(B)
A= $suffixB= not $opt{"no_implicit_accessor_calls"}
ABresult
0X0
100
111
193 # Try to invoke a subroutine by the given name (only if we've got a suffix)
194 0 foreach my $k (@mkeys) {
195 0 my $method = sanitize_subroutine_name ($k);
196 0 ▶ $found //= eval { $o->$method(@_) } if blessed ($o) && $o->can($method);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($o) and $o->can($method) 0 0 0
Condition0%0/6
builtin::blessed($o) and $o->can($method)
!ll&&!rl&&r
000
$found //= eval { do { $o->$method(@_) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($o) and $o->can($method)
builtin::blessed($o) $o->can($method)
MC/DC0%0/2
$found //= eval { do { $o->$method(@_) } }
$found eval { do { $o->$method(@_) } }
Truth table0%0/3
A and B
A= builtin::blessed($o)B= $o->can($method)
ABresult
0X0
100
111
Truth table0%0/3
A //= B
A= $foundB= eval { do { $o->$method(@_) } }
ABresult
1X1
011
000
197 0 ▶ last if defined $found;
Branch: 1 branch
BranchTrueFalseTotal
if defined $found 0 0 0
198 }
199 }
200 0 ▶ $found = eval { hash_lookup_staged( %opt, keys=> [@mkeys] ) } unless defined ($found);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $found 0 0 0
201 0 ▶ push @res, ($found) if defined($found) && !$@;
Branch: 1 branch
BranchTrueFalseTotal
if defined $found and not $@ 0 0 0
Condition0%0/3
defined $found and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
defined $found and not $@
defined $found not $@
Truth table0%0/3
A and not(B)
A= defined $foundB= not $@
ABresult
0X0
100
111
202 }
203 0 @res = tidy_arrayify(@res);
204  
205 # say STDERR " Smart-lookup got (raw) : " . np @res if $debug;
206  
207 # If are asked to do so, make sure we return an array-reference
208 # if ($opt{want_reftype} eq 'ARRAY') {
209 # $res = [tidy_arrayify($res)];
210 # $res = [ Text::ParseWords::quotewords('\s+', 0, @$res) ] if $opt{'parsewords'};
211 # }
212  
213 # Parse words and make them into array items (if asked to do so)
214 #@res = tidy_arrayify(quotewords('\s+', 0, @res)) if $opt{'parsewords'};
215  
216 # say STDERR " Smart-lookup got (after-parsewords) : " . np @res if $debug;
217  
218 0 ▶ die "Can't lookup any of the given keys [@keys]!" unless scalar(@res);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @res 0 0 0
219  
220 0 ▶ wantarray ? (@res) : \@res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
221 # return [ @res ] if $opt{want_reftype} eq 'ARRAY' ;
222 # return unless @res; # Got no results at all. Signal that.
223 # return $res[0] if @res == 1; # If we've got only one value, then there is no ambiguity. Just return that.
224 #
225 # if ( $opt{want_reftype} eq 'HASH' ) {
226 # my %res = map {; ref ($_) =~ /HASH/ix ? ( %{$_} ) : () } reverse @res; # effectively shallow-merge the resulting hashes
227 # return +{ %res };
228 # }
229 #
230 # # At this stage, even if we have more than one value, we only return the first found.
231 # # CONSIDER: raising an error, perhaps.
232 # return $res[0];
233 }
234  
235  
236 #######################################
237 0 ▶sub _normalize_fallback_opts {
Subroutine _normalize_fallback_opts: not called CC=20 SCAR=60.4
238 #######################################
239 0 local $_;
240 0 my $o = shift;
241 0 ▶ my %opt = %{ ref $_[0] eq 'HASH' ? shift : +{} };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
242  
243 0 ▶ unless ( exists $opt{_normalized_} && ($opt{_normalized_} // 0) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opt{"_normalized_"} and $opt{"_normalized_"} // 0) 0 0 0
Condition0%0/5
exists $opt{"_normalized_"} and $opt{"_normalized_"} // 0
!ll&&!rl&&r
000
$opt{"_normalized_"} // 0
l!l
00
MC/DC0%0/2
exists $opt{"_normalized_"} and $opt{"_normalized_"} // 0
exists $opt{"_normalized_"} $opt{"_normalized_"}
Truth table0%0/3
A and B
A= exists $opt{"_normalized_"}B= $opt{"_normalized_"}
ABresult
0X0
100
111
244 # these may be overridden by the caller.
245 0 %opt = ( payload=>1, author_specific=>1, generic=>1, %opt );
246 0 ▶ my $fbs = eval { $o->_fallback_settings(%opt) } // eval { $o->fallback_settings(%opt) } // +{};
Condition0%0/5
(eval { do { $o->_fallback_settings(%opt) } } // eval { do { $o->fallback_settings(%opt) } }) // {}
l!l
00
eval { do { $o->_fallback_settings(%opt) } } // eval { do { $o->fallback_settings(%opt) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
(eval { do { $o->_fallback_settings(%opt) } } // eval { do { $o->fallback_settings(%opt) } }) // {}
eval { do { $o->_fallback_settings(%opt) } } eval { do { $o->fallback_settings(%opt) } }
Truth table0%0/3
A // B
A= eval { do { $o->_fallback_settings(%opt) } }B= eval { do { $o->fallback_settings(%opt) } }
ABresult
1X1
011
000
247 0 %opt = ( %$fbs, %opt );
248  
249 0 ▶ my $isam = exists $opt{isam} ? $opt{isam} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'isam'} ? : 0 0 0
250 0 $isam = "$isam"; # We are only able to consider plain scalars.
251  
252  
253 #say STDERR "metam : " . np %meta;
254 #say STDERR "isam : '$isam'";
255  
256 0 ▶ my $rt = $opt{want_reftype} // '';
Condition0%0/2
$opt{"want_reftype"} // ""
l!l
00
MC/DC0%0/1
$opt{"want_reftype"} // ""
$opt{"want_reftype"}
Truth table0%0/2
A
A= $opt{"want_reftype"}
Aresult
11
00
257 0 ▶ $rt = 'ARRAY' if $opt{multivalue} || any { defined && /^ARRAY/ix } ($rt, $isam);
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if $opt{"multivalue"} or &any(sub { defined $_ and /^ARRAY/iux; } , $rt, $isam) 0 0 0
defined $_ and /^ARRAY/iux 0 0 0
Condition0%0/3
$opt{"multivalue"} or &any(sub { defined $_ and /^ARRAY/iux; } , $rt, $isam)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{"multivalue"} or &any(sub { defined $_ and /^ARRAY/iux; } , $rt, $isam)
$opt{"multivalue"} &any(sub { defined $_ and /^ARRAY/iux; } , $rt, $isam)
Truth table0%0/3
A or B
A= $opt{"multivalue"}B= &any(sub { defined $_ and /^ARRAY/iux; } , $rt, $isam)
ABresult
1X1
011
000
258 0 ▶ $rt = 'HASH' if any { defined && /^HASH/ix } ($rt, $isam);
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { defined $_ and /^HASH/iux; } , $rt, $isam) 0 0 0
defined $_ and /^HASH/iux 0 0 0
259 0 $opt{want_reftype} = $rt;
260 0 ▶ $opt{multivalue} //= $rt =~ /^ARRAY/ix || 0;
Condition0%0/4
$opt{"multivalue"} //= $rt =~ /^ARRAY/iux || 0
l!l
00
$rt =~ /^ARRAY/iux || 0
l!l
00
MC/DC0%0/1
$opt{"multivalue"} //= $rt =~ /^ARRAY/iux || 0
$opt{"multivalue"}
Truth table0%0/2
A
A= $opt{"multivalue"}
Aresult
11
00
261 0 ▶ $opt{parsewords} //= $rt =~ /^ARRAY/ix || 0;
Condition0%0/4
$opt{"parsewords"} //= $rt =~ /^ARRAY/iux || 0
l!l
00
$rt =~ /^ARRAY/iux || 0
l!l
00
MC/DC0%0/1
$opt{"parsewords"} //= $rt =~ /^ARRAY/iux || 0
$opt{"parsewords"}
Truth table0%0/2
A
A= $opt{"parsewords"}
Aresult
11
00
262 $opt{keys} = [ tidy_arrayify( # we are quite forgiving in terms of specifiying keys/aliases
263 $opt{key}, $opt{keys},
264 $opt{name}, $opt{names},
265 $opt{aka}, $opt{alias}, $opt{aliases}, )
266 0 ];
267 }
268  
269 # This is done even if opts are already normalized.
270 0 ▶ $opt{keys} = [ tidy_arrayify($opt{keys}, splice @_) ] if delete($opt{args_are_keys}) // 0;
Branch: 1 branch
BranchTrueFalseTotal
if delete $opt{"args_are_keys"} // 0 0 0 0
Condition0%0/2
delete $opt{"args_are_keys"} // 0
l!l
00
MC/DC0%0/1
delete $opt{"args_are_keys"} // 0
delete $opt{"args_are_keys"}
Truth table0%0/2
A
A= delete $opt{"args_are_keys"}
Aresult
11
00
271 0 my @keys = tidy_arrayify($opt{keys});
272 0 $opt{debug} = 0;
273 # $opt{debug} = grep { m/(installer|stopword)/ix } @keys;
274  
275 0 ▶ if ( !$opt{_normalized_} ){ # DEBUG
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"_normalized_"}) 0 0 0
276 0 my %mopt = (%opt);
277 0 delete @mopt{qw(sources)};
278 #say STDERR "mopt : " . np %mopt;
279 }
280  
281 0 $opt{_normalized_} = 1;
282 0 ▶ return wantarray ? ($o, %opt) : \%opt;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
283 }
284  
285  
286  
287 1 1;
288  
289 =pod
290  
291 =encoding UTF-8
292  
293 =head1 NAME
294  
295 Banal::Role::Fallback::Tiny - A tiny role that provides a 'fallback' method which helps building default values for object attributes.
296  
297 =head1 VERSION
298  
299 version 0.001
300  
301 =head1 SYNOPSIS
302  
303 Role::Tiny::With;
304 with Banal::Role::Fallback::Tiny;
305  
306 has username => (
307 is => ro,
308 isa => Str,
309 lazy => 1,
310 default => sub { fallback(keys=> [qw(username user)}
311 );
312  
313 =head1 DESCRIPTION
314  
315 =for stopwords isa lazy ro Str
316  
317 =for stopwords TABULO
318 =for stopwords GitHub DZIL
319  
320 This is a tiny role that provides a 'fallback' method for building default values for your attributes.
321  
322 =head2 WARNING
323  
324 Please note that, although this module needs to be on CPAN for obvious reasons,
325 it is really intended to be a collection of personal preferences, which are
326 expected to be in great flux, at least for the time being.
327  
328 Therefore, please do NOT base your own distributions on this one, since anything
329 can change at any moment without prior notice, while I get accustomed to dzil
330 myself and form those preferences in the first place...
331 Absolutely nothing in this distribution is guaranteed to remain constant or
332 be maintained at this point. Who knows, I may even give up on dzil altogether...
333  
334 You have been warned.
335  
336 =head1 SEE ALSO
337  
338 =over 4
339  
340 =item *
341  
342 L<Role::Tiny>
343  
344 =back
345  
346 =head1 SUPPORT
347  
348 Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Banal-Role-Fallback>
349 (or L<bug-Banal-Role-Fallback@rt.cpan.org|mailto:bug-Banal-Role-Fallback@rt.cpan.org>).
350  
351 =head1 AUTHOR
352  
353 Ayhan ULUSOY <dev@tabulo.net>
354  
355 =head1 COPYRIGHT AND LICENSE
356  
357 This software is copyright (c) 2018 by Ayhan ULUSOY.
358  
359 This is free software; you can redistribute it and/or modify it under
360 the same terms as the Perl 5 programming language system itself.
361  
362 =cut
363  
364 __END__
↑ Summary Fallback/Moo.pm »