| 1 | package Business::NAB::Role::AttributeContainer; | ||||||||||
| 2 | 8 | $Business::NAB::Role::AttributeContainer::VERSION = '0.11'; | |||||||||
| 3 | # undocument role | ||||||||||
| 4 | |||||||||||
| 5 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use feature qw/ signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 8 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 8 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 8 | ▶ | no warnings qw/ experimental::signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 8 | ▶ | use Module::Load; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 8 | ▶ | use Business::NAB::Types qw/ decamelize /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 11 | ▶ | sub load_attributes ( | ||||||||
|
Subroutine
load_attributes: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 17 | $self, | ||||||||||
| 18 | $parent, | ||||||||||
| 19 | @subclasses, | ||||||||||
| 20 | ) { | ||||||||||
| 21 | 11 | foreach my $record_type ( @subclasses ) { | |||||||||
| 22 | |||||||||||
| 23 | 35 | load( $parent . "::$record_type" ); | |||||||||
| 24 | |||||||||||
| 25 | 35 | my $attr = decamelize( $record_type ); | |||||||||
| 26 | 35 | my $class = "${parent}::$record_type"; | |||||||||
| 27 | |||||||||||
| 28 | 35 | subtype $record_type | |||||||||
| 29 | => as "ArrayRef[$class]"; | ||||||||||
| 30 | |||||||||||
| 31 | coerce $record_type | ||||||||||
| 32 | => from "ArrayRef[HashRef|$class]" | ||||||||||
| 33 | 48 | ▶ | => via { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 34 | |||||||||||
| 35 | # when a new thing is pushed onto the array we need to coerce | ||||||||||
| 36 | # it from a HashRef to the instance of the class, but if it's | ||||||||||
| 37 | # already an instance of the class then pass it straight through | ||||||||||
| 38 | my @objects = map { | ||||||||||
| 39 | 165 | ▶ | ref $_ eq $class | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | ? $_ | ||||||||||
| 41 | : $class->new( $_ ) | ||||||||||
| 42 | 48 | } @{ $_ }; | |||||||||
| 43 | |||||||||||
| 44 | 48 | [ @objects ]; | |||||||||
| 45 | } | ||||||||||
| 46 | => from "ArrayRef[Any]" | ||||||||||
| 47 | 1 | ▶ | => via { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 48 | 1 | [ $class->new( $_->@* ) ] | |||||||||
| 49 | } | ||||||||||
| 50 | 35 | ; | |||||||||
| 51 | |||||||||||
| 52 | $parent->meta->add_attribute( | ||||||||||
| 53 | $attr, | ||||||||||
| 54 | { | ||||||||||
| 55 | traits => [ 'Array' ], | ||||||||||
| 56 | is => 'rw', | ||||||||||
| 57 | isa => $record_type, | ||||||||||
| 58 | coerce => 1, | ||||||||||
| 59 | 53 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 35 | handles => { | |||||||||
| 61 | "add_${attr}" => 'push', | ||||||||||
| 62 | }, | ||||||||||
| 63 | }, | ||||||||||
| 64 | ); | ||||||||||
| 65 | } | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 8 | 1; | |||||||||