| 1 | package CCfnX::Attachments; | ||||||||||
| 2 | 2 | ▶ | use Moose::Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 2 | Moose::Exporter->setup_import_methods( | |||||||||
| 5 | with_meta => [ 'attachment' ], | ||||||||||
| 6 | ); | ||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | sub attachment { | ||||||||
|
Subroutine
attachment: called CC=5 SCAR=16.9
Pod
undocumented
| |||||||||||
| 9 | 3 | ▶ | Moose->throw_error( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 10 | 'Usage: attachment \'name\' => (type => \'Type\', documentation => \'\',' . | ||||||||||
| 11 | ' provides => { param => key_from_attachment, ... })' | ||||||||||
| 12 | ) if (@_ < 2); | ||||||||||
| 13 | 3 | 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 | 3 | generates_params => [ keys %{ $options{provides} } ], | |||||||||
| 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 | 3 | foreach my $attribute (keys %{ $options{ provides } }){ | |||||||||
| 29 | 6 | my $lookup_in_attachment = $options{ provides }->{$attribute}; | |||||||||
| 30 | |||||||||||
| 31 | 6 | ▶ | if ($meta->find_attribute_by_name($attribute)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | Moose->throw_error("An attribute with name $attribute already exists"); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 5 | my @extra_traits = (); | |||||||||
| 36 | 5 | ▶ | if (substr($attribute,0,1) eq '-'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | # Strip off the '-' in the attribute name | ||||||||||
| 38 | 0 | substr($attribute,0,1) = ''; | |||||||||
| 39 | } else { | ||||||||||
| 40 | 5 | 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 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 50 | 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 | 5 | ); | |||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 2 | 1; | |||||||||