line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
106
|
|
|
106
|
|
640
|
|
|
106
|
|
|
|
|
203
|
|
|
106
|
|
|
|
|
634
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Class::Method::Modifiers qw(install_modifier); |
7
|
106
|
|
|
106
|
|
820
|
|
|
106
|
|
|
|
|
217
|
|
|
106
|
|
|
|
|
9630
|
|
8
|
|
|
|
|
|
|
my $target = caller; |
9
|
|
|
|
|
|
|
|
10
|
174
|
|
|
174
|
|
1477
|
my $around = do {no strict 'refs'; \&{"${target}::around"}}; |
11
|
|
|
|
|
|
|
my $fix_args = []; |
12
|
106
|
|
|
106
|
|
799
|
my $fix_opts = []; |
|
106
|
|
|
|
|
260
|
|
|
106
|
|
|
|
|
56572
|
|
|
174
|
|
|
|
|
3368
|
|
|
174
|
|
|
|
|
268
|
|
|
174
|
|
|
|
|
721
|
|
13
|
174
|
|
|
|
|
363
|
|
14
|
174
|
|
|
|
|
316
|
install_modifier( |
15
|
|
|
|
|
|
|
$target, 'around', 'has', |
16
|
|
|
|
|
|
|
sub { |
17
|
|
|
|
|
|
|
my ($orig, $attr, %opts) = @_; |
18
|
|
|
|
|
|
|
|
19
|
341
|
|
|
341
|
|
8444
|
return $orig->($attr, %opts) |
20
|
|
|
|
|
|
|
unless exists $opts{fix_arg} || exists $opts{fix_opt}; |
21
|
|
|
|
|
|
|
|
22
|
341
|
100
|
100
|
|
|
1480
|
$opts{is} //= 'ro'; |
23
|
|
|
|
|
|
|
$opts{init_arg} //= $attr; |
24
|
321
|
|
50
|
|
|
1747
|
|
25
|
321
|
|
66
|
|
|
1262
|
my $arg = {key => $opts{init_arg}}; |
26
|
|
|
|
|
|
|
|
27
|
321
|
|
|
|
|
835
|
if ($opts{fix_arg}) { |
28
|
|
|
|
|
|
|
$opts{required} //= 1; |
29
|
321
|
100
|
|
|
|
970
|
$arg->{collect} = 1 if $opts{fix_arg} eq 'collect'; |
30
|
266
|
|
50
|
|
|
1417
|
push @$fix_args, $arg; |
31
|
266
|
100
|
|
|
|
912
|
delete $opts{fix_arg}; |
32
|
266
|
|
|
|
|
640
|
} |
33
|
266
|
|
|
|
|
558
|
|
34
|
|
|
|
|
|
|
if ($opts{fix_opt}) { |
35
|
|
|
|
|
|
|
$arg->{collect} = 1 if $opts{fix_opt} eq 'collect'; |
36
|
321
|
100
|
|
|
|
922
|
push @$fix_opts, $arg; |
37
|
55
|
100
|
|
|
|
179
|
delete $opts{fix_opt}; |
38
|
55
|
|
|
|
|
108
|
} |
39
|
55
|
|
|
|
|
113
|
|
40
|
|
|
|
|
|
|
$orig->($attr, %opts); |
41
|
|
|
|
|
|
|
} |
42
|
321
|
|
|
|
|
1702
|
); |
43
|
|
|
|
|
|
|
|
44
|
174
|
|
|
|
|
1559
|
$around->( |
45
|
|
|
|
|
|
|
'BUILDARGS', |
46
|
|
|
|
|
|
|
sub { |
47
|
|
|
|
|
|
|
my $orig = shift; |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
660
|
|
|
660
|
|
329427
|
|
50
|
660
|
|
|
|
|
1391
|
return $orig->($self, @_) unless @$fix_args || @$fix_opts; |
51
|
|
|
|
|
|
|
|
52
|
660
|
50
|
66
|
|
|
2371
|
my $args = {}; |
53
|
|
|
|
|
|
|
|
54
|
660
|
|
|
|
|
1224
|
for my $arg (@$fix_args) { |
55
|
|
|
|
|
|
|
last unless @_; |
56
|
660
|
|
|
|
|
2051
|
my $key = $arg->{key}; |
57
|
955
|
100
|
|
|
|
2049
|
if ($arg->{collect}) { |
58
|
940
|
|
|
|
|
1731
|
$args->{$key} = [splice @_, 0, @_]; |
59
|
940
|
100
|
|
|
|
2019
|
last; |
60
|
13
|
|
|
|
|
49
|
} |
61
|
13
|
|
|
|
|
26
|
$args->{$key} = shift; |
62
|
|
|
|
|
|
|
} |
63
|
927
|
|
|
|
|
2246
|
|
64
|
|
|
|
|
|
|
my $orig_args = $self->$orig(@_); |
65
|
|
|
|
|
|
|
|
66
|
660
|
|
|
|
|
2263
|
for my $arg (@$fix_opts) { |
67
|
|
|
|
|
|
|
my $key = $arg->{key}; |
68
|
660
|
|
|
|
|
4712
|
if ($arg->{collect}) { |
69
|
319
|
|
|
|
|
558
|
$args->{$key} = $orig_args; |
70
|
319
|
100
|
|
|
|
1097
|
last; |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
71
|
59
|
|
|
|
|
106
|
} |
72
|
59
|
|
|
|
|
107
|
elsif (exists $orig_args->{"-$key"}) { |
73
|
|
|
|
|
|
|
$args->{$key} = delete $orig_args->{"-$key"}; |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
4
|
elsif (exists $orig_args->{$key}) { |
76
|
|
|
|
|
|
|
$args->{$key} = delete $orig_args->{$key}; |
77
|
|
|
|
|
|
|
} |
78
|
77
|
|
|
|
|
217
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$args; |
81
|
|
|
|
|
|
|
} |
82
|
660
|
|
|
|
|
9504
|
); |
83
|
|
|
|
|
|
|
} |
84
|
174
|
|
|
|
|
53315
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=pod |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Catmandu::Fix::Has - helper class for creating Fix-es with (optional) parameters |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package Catmandu::Fix::foo; |
97
|
|
|
|
|
|
|
use Moo; |
98
|
|
|
|
|
|
|
use Catmandu::Fix::Has; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
has greeting => (fix_arg => 1); # required parameter 1 |
101
|
|
|
|
|
|
|
has message => (fix_arg => 1); # required parameter 2 |
102
|
|
|
|
|
|
|
has eol => (fix_opt => 1 , default => sub {'!'} ); # optional parameter 'eol' with default '!' |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub fix { |
105
|
|
|
|
|
|
|
my ($self,$data) = @_; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
print STDERR $self->greeting . ", " . $self->message . $self->eol . "\n"; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$data; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 PARAMETERS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item fix_arg |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Required argument when set to 1. The Fix containing the code fragment below needs |
121
|
|
|
|
|
|
|
two arguments. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
use Catmandu::Fix::Has; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
has message => (fix_arg => 1); # required parameter 1 |
126
|
|
|
|
|
|
|
has number => (fix_arg => 1); # required parameter 2 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
When the fix_arg is set to 'collect', then all arguments are read into an |
129
|
|
|
|
|
|
|
array. The Fix containing the code fragment below needs at least 1 or more |
130
|
|
|
|
|
|
|
arguments. All arguments will get collected into the C<messages> array: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
use Catmandu::Fix::Has; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
has messages => (fix_arg => 'collect'); # required parameter |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item fix_opt |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Optional named argument when set to 1. The Fix containing the code fragment |
139
|
|
|
|
|
|
|
below can have two optional arguments C<message: ...>, C<number: ...>: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
use Catmandu::Fix::Has; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
has message => (fix_opt => 1); # optional parameter 1 |
144
|
|
|
|
|
|
|
has number => (fix_opt => 1); # optional parameter 2 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
When the fix_opt is set to 'collect', then all optional argument are read into |
147
|
|
|
|
|
|
|
an array. The Fix containing the code fragment below needs at least 1 or more |
148
|
|
|
|
|
|
|
arguments. All arguments will get collected into the C<options> array: |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
use Catmandu::Fix::Has; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
has options => (fix_opt => 'collect'); # optional parameter |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SEE ALSO |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Catmandu::Fix> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|