line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CCfnX::Attachments; |
2
|
1
|
|
|
1
|
|
172946
|
use Moose::Exporter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
5
|
|
|
|
|
|
|
with_meta => [ 'attachment' ], |
6
|
|
|
|
|
|
|
); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub attachment { |
9
|
2
|
50
|
|
2
|
0
|
49757
|
Moose->throw_error( |
10
|
|
|
|
|
|
|
'Usage: attachment \'name\' => (type => \'Type\', documentation => \'\',' . |
11
|
|
|
|
|
|
|
' provides => { param => key_from_attachment, ... })' |
12
|
|
|
|
|
|
|
) if (@_ < 2); |
13
|
2
|
|
|
|
|
13
|
my ( $meta, $name, %options ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Add the attachment |
16
|
|
|
|
|
|
|
$meta->add_attribute( |
17
|
|
|
|
|
|
|
$name, |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => 'Str', |
20
|
|
|
|
|
|
|
type => $options{ type }, |
21
|
|
|
|
|
|
|
traits => [ 'Attachable' ], |
22
|
2
|
|
|
|
|
8
|
generates_params => [ keys %{ $options{provides} } ], |
|
2
|
|
|
|
|
15
|
|
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Every attachment will declare that it provides some extra parameters in the provides |
26
|
|
|
|
|
|
|
# these will be converted in attributes. If they start with "-", then they will not be |
27
|
|
|
|
|
|
|
# StackParameters, that is they will not be accessible in CF via a Ref. |
28
|
2
|
|
|
|
|
13996
|
foreach my $attribute (keys %{ $options{ provides } }){ |
|
2
|
|
|
|
|
19
|
|
29
|
2
|
|
|
|
|
5
|
my $lookup_in_attachment = $options{ provides }->{$attribute}; |
30
|
|
|
|
|
|
|
|
31
|
2
|
100
|
|
|
|
13
|
if ($meta->find_attribute_by_name($attribute)) { |
32
|
1
|
|
|
|
|
69
|
Moose->throw_error("An attribute with name $attribute already exists"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
78
|
my @extra_traits = (); |
36
|
1
|
50
|
|
|
|
6
|
if (substr($attribute,0,1) eq '-'){ |
37
|
|
|
|
|
|
|
# Strip off the '-' in the attribute name |
38
|
0
|
|
|
|
|
0
|
substr($attribute,0,1) = ''; |
39
|
|
|
|
|
|
|
} else { |
40
|
1
|
|
|
|
|
4
|
push @extra_traits, 'StackParameter'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$meta->add_attribute( |
44
|
|
|
|
|
|
|
$attribute, |
45
|
|
|
|
|
|
|
is => 'rw', |
46
|
|
|
|
|
|
|
isa => 'Any', |
47
|
|
|
|
|
|
|
lazy => 1, |
48
|
|
|
|
|
|
|
traits => [ 'NoGetopt', 'Attached', @extra_traits ], |
49
|
|
|
|
|
|
|
default => sub { |
50
|
0
|
|
|
0
|
|
|
my $params = $_[0]; |
51
|
0
|
|
|
|
|
|
my $param = $params->meta->find_attribute_by_name($name); |
52
|
0
|
|
|
|
|
|
return $param->get_info($params->$name, $lookup_in_attachment) |
53
|
|
|
|
|
|
|
}, |
54
|
1
|
|
|
|
|
9
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |