| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Object::Role::Arguable; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33032
|
use 5.014; |
|
|
1
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use routines; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
2400
|
use Moo::Role; |
|
|
1
|
|
|
|
|
9898
|
|
|
|
1
|
|
|
|
|
7
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Data::Object::Role::Buildable'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
requires 'argslist'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# BUILD |
|
18
|
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
0
|
49365
|
method build_arg($arg) { |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
4
|
|
|
20
|
2
|
50
|
|
|
|
8
|
if (ref $arg eq 'ARRAY') { |
|
21
|
2
|
|
|
|
|
7
|
return $self->packargs(@$arg); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
else { |
|
24
|
0
|
|
|
|
|
0
|
return $arg; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# METHODS |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
|
|
3
|
1
|
5865
|
method packargs(@args) { |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
6
|
|
|
31
|
3
|
|
|
|
|
5
|
my $data = {}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
58
|
for my $expr ($self->argslist) { |
|
34
|
6
|
50
|
|
|
|
30
|
last if !@args; |
|
35
|
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
16
|
my $regx = qr/^(\W*)(\w+)$/; |
|
37
|
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
33
|
my ($type, $attr) = $expr =~ $regx; |
|
39
|
|
|
|
|
|
|
|
|
40
|
6
|
100
|
|
|
|
19
|
if (!$type) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
14
|
$data->{$attr} = shift(@args); |
|
42
|
|
|
|
|
|
|
} elsif ($type eq '@') { |
|
43
|
3
|
|
|
|
|
8
|
$data->{$attr} = [@args]; |
|
44
|
3
|
|
|
|
|
9
|
last; |
|
45
|
|
|
|
|
|
|
} elsif ($type eq '%') { |
|
46
|
0
|
|
|
|
|
0
|
$data->{$attr} = {@args}; |
|
47
|
0
|
|
|
|
|
0
|
last; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
19
|
return $data; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
1
|
109
|
method unpackargs() { |
|
|
1
|
|
|
|
|
2
|
|
|
55
|
1
|
|
|
|
|
2
|
my @args; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
18
|
for my $expr ($self->argslist) { |
|
58
|
2
|
|
|
|
|
23
|
my $regx = qr/^(\W*)(\w+)$/; |
|
59
|
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
12
|
my ($type, $attr) = $expr =~ $regx; |
|
61
|
|
|
|
|
|
|
|
|
62
|
2
|
100
|
|
|
|
17
|
if (!$type) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
6
|
push @args, $self->$attr; |
|
64
|
|
|
|
|
|
|
} elsif ($type eq '@') { |
|
65
|
1
|
50
|
|
|
|
5
|
push @args, @{$self->$attr} if $self->$attr; |
|
|
1
|
|
|
|
|
5
|
|
|
66
|
1
|
|
|
|
|
3
|
last; |
|
67
|
|
|
|
|
|
|
} elsif ($type eq '%') { |
|
68
|
0
|
0
|
|
|
|
0
|
push @args, @{$self->$attr} if $self->$attr; |
|
|
0
|
|
|
|
|
0
|
|
|
69
|
0
|
|
|
|
|
0
|
last; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
13
|
return @args; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=encoding utf8 |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Data::Object::Role::Arguable |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 ABSTRACT |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Arguable Role for Perl 5 Plugin Classes |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
package Example; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
use Moo; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
with 'Data::Object::Role::Arguable'; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
has name => ( |
|
101
|
|
|
|
|
|
|
is => 'ro' |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
has options => ( |
|
105
|
|
|
|
|
|
|
is => 'ro' |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub argslist { |
|
109
|
|
|
|
|
|
|
('name', '@options') |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
package main; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $example = Example->new(['james', 'red', 'white', 'blue']); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This package provides a mechanism for unpacking an argument list and creating a |
|
121
|
|
|
|
|
|
|
data structure suitable for passing to the consumer constructor. The |
|
122
|
|
|
|
|
|
|
C<argslist> routine should return a list of attribute names in the order to be |
|
123
|
|
|
|
|
|
|
parsed. An attribute name maybe prefixed with B<"@"> to denote that all remaining |
|
124
|
|
|
|
|
|
|
items should be assigned to an arrayref, e.g. C<@options>, or B<"%"> to denote |
|
125
|
|
|
|
|
|
|
that all remaining items should be assigned to a hashref, e.g. C<%options>. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 LIBRARIES |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This package uses type constraints from: |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<Types::Standard> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 METHODS |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This package implements the following methods: |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 packargs |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
packargs() : HashRef |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
The packargs method uses C<argslist> to return a data structure suitable for |
|
148
|
|
|
|
|
|
|
passing to the consumer constructor. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item packargs example #1 |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
package main; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $example = Example->new; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $attributes = $example->packargs('james', 'red', 'white', 'blue'); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 unpackargs |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
unpackargs(Any @args) : (Any) |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The unpackargs method uses C<argslist> to return a list of arguments from the |
|
169
|
|
|
|
|
|
|
consumer class instance in the appropriate order. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over 4 |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item unpackargs example #1 |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
package main; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $example = Example->new(['james', 'red', 'white', 'blue']); |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $arguments = [$example->unpackargs]; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Al Newkirk, C<awncorp@cpan.org> |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 LICENSE |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Copyright (C) 2011-2019, Al Newkirk, et al. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the terms |
|
194
|
|
|
|
|
|
|
of the The Apache License, Version 2.0, as elucidated in the L<"license |
|
195
|
|
|
|
|
|
|
file"|https://github.com/iamalnewkirk/foobar/blob/master/LICENSE>. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 PROJECT |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
L<Wiki|https://github.com/iamalnewkirk/foobar/wiki> |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L<Project|https://github.com/iamalnewkirk/foobar> |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L<Initiatives|https://github.com/iamalnewkirk/foobar/projects> |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L<Milestones|https://github.com/iamalnewkirk/foobar/milestones> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L<Contributing|https://github.com/iamalnewkirk/foobar/blob/master/CONTRIBUTE.md> |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L<Issues|https://github.com/iamalnewkirk/foobar/issues> |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |