line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
106
|
|
|
106
|
|
664
|
|
|
106
|
|
|
|
|
184
|
|
|
106
|
|
|
|
|
645
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Class::Method::Modifiers qw(install_modifier); |
7
|
106
|
|
|
106
|
|
806
|
|
|
106
|
|
|
|
|
227
|
|
|
106
|
|
|
|
|
9752
|
|
8
|
|
|
|
|
|
|
my $target = caller; |
9
|
|
|
|
|
|
|
|
10
|
174
|
|
|
174
|
|
1394
|
my $around = do {no strict 'refs'; \&{"${target}::around"}}; |
11
|
|
|
|
|
|
|
my $fix_args = []; |
12
|
106
|
|
|
106
|
|
762
|
my $fix_opts = []; |
|
106
|
|
|
|
|
237
|
|
|
106
|
|
|
|
|
56302
|
|
|
174
|
|
|
|
|
3384
|
|
|
174
|
|
|
|
|
331
|
|
|
174
|
|
|
|
|
679
|
|
13
|
174
|
|
|
|
|
354
|
|
14
|
174
|
|
|
|
|
287
|
install_modifier( |
15
|
|
|
|
|
|
|
$target, 'around', 'has', |
16
|
|
|
|
|
|
|
sub { |
17
|
|
|
|
|
|
|
my ($orig, $attr, %opts) = @_; |
18
|
|
|
|
|
|
|
|
19
|
341
|
|
|
341
|
|
8324
|
return $orig->($attr, %opts) |
20
|
|
|
|
|
|
|
unless exists $opts{fix_arg} || exists $opts{fix_opt}; |
21
|
|
|
|
|
|
|
|
22
|
341
|
100
|
100
|
|
|
1495
|
$opts{is} //= 'ro'; |
23
|
|
|
|
|
|
|
$opts{init_arg} //= $attr; |
24
|
321
|
|
50
|
|
|
1796
|
|
25
|
321
|
|
66
|
|
|
1326
|
my $arg = {key => $opts{init_arg}}; |
26
|
|
|
|
|
|
|
|
27
|
321
|
|
|
|
|
752
|
if ($opts{fix_arg}) { |
28
|
|
|
|
|
|
|
$opts{required} //= 1; |
29
|
321
|
100
|
|
|
|
917
|
$arg->{collect} = 1 if $opts{fix_arg} eq 'collect'; |
30
|
266
|
|
50
|
|
|
1398
|
push @$fix_args, $arg; |
31
|
266
|
100
|
|
|
|
868
|
delete $opts{fix_arg}; |
32
|
266
|
|
|
|
|
610
|
} |
33
|
266
|
|
|
|
|
536
|
|
34
|
|
|
|
|
|
|
if ($opts{fix_opt}) { |
35
|
|
|
|
|
|
|
$arg->{collect} = 1 if $opts{fix_opt} eq 'collect'; |
36
|
321
|
100
|
|
|
|
990
|
push @$fix_opts, $arg; |
37
|
55
|
100
|
|
|
|
196
|
delete $opts{fix_opt}; |
38
|
55
|
|
|
|
|
104
|
} |
39
|
55
|
|
|
|
|
93
|
|
40
|
|
|
|
|
|
|
$orig->($attr, %opts); |
41
|
|
|
|
|
|
|
} |
42
|
321
|
|
|
|
|
1382
|
); |
43
|
|
|
|
|
|
|
|
44
|
174
|
|
|
|
|
1545
|
$around->( |
45
|
|
|
|
|
|
|
'BUILDARGS', |
46
|
|
|
|
|
|
|
sub { |
47
|
|
|
|
|
|
|
my $orig = shift; |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
660
|
|
|
660
|
|
324741
|
|
50
|
660
|
|
|
|
|
1258
|
return $orig->($self, @_) unless @$fix_args || @$fix_opts; |
51
|
|
|
|
|
|
|
|
52
|
660
|
50
|
66
|
|
|
2194
|
my $args = {}; |
53
|
|
|
|
|
|
|
|
54
|
660
|
|
|
|
|
1186
|
for my $arg (@$fix_args) { |
55
|
|
|
|
|
|
|
last unless @_; |
56
|
660
|
|
|
|
|
1524
|
my $key = $arg->{key}; |
57
|
955
|
100
|
|
|
|
1871
|
if ($arg->{collect}) { |
58
|
940
|
|
|
|
|
1643
|
$args->{$key} = [splice @_, 0, @_]; |
59
|
940
|
100
|
|
|
|
1943
|
last; |
60
|
13
|
|
|
|
|
49
|
} |
61
|
13
|
|
|
|
|
30
|
$args->{$key} = shift; |
62
|
|
|
|
|
|
|
} |
63
|
927
|
|
|
|
|
2141
|
|
64
|
|
|
|
|
|
|
my $orig_args = $self->$orig(@_); |
65
|
|
|
|
|
|
|
|
66
|
660
|
|
|
|
|
2043
|
for my $arg (@$fix_opts) { |
67
|
|
|
|
|
|
|
my $key = $arg->{key}; |
68
|
660
|
|
|
|
|
4315
|
if ($arg->{collect}) { |
69
|
319
|
|
|
|
|
472
|
$args->{$key} = $orig_args; |
70
|
319
|
100
|
|
|
|
968
|
last; |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
71
|
59
|
|
|
|
|
126
|
} |
72
|
59
|
|
|
|
|
107
|
elsif (exists $orig_args->{"-$key"}) { |
73
|
|
|
|
|
|
|
$args->{$key} = delete $orig_args->{"-$key"}; |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
7
|
elsif (exists $orig_args->{$key}) { |
76
|
|
|
|
|
|
|
$args->{$key} = delete $orig_args->{$key}; |
77
|
|
|
|
|
|
|
} |
78
|
77
|
|
|
|
|
195
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$args; |
81
|
|
|
|
|
|
|
} |
82
|
660
|
|
|
|
|
9341
|
); |
83
|
|
|
|
|
|
|
} |
84
|
174
|
|
|
|
|
52885
|
|
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
|
|
|
|
|
|
|
|