| 1 | package Graphics::Primitive::Container; | ||||||||||
| 2 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use MooseX::Storage; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | with Storage (format => 'JSON', io => 'File'); | |||||||||
| 6 | |||||||||||
| 7 | 4 | ▶ | use Graphics::Primitive::ComponentList; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use Forest::Tree; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | extends 'Graphics::Primitive::Component'; | |||||||||
| 12 | |||||||||||
| 13 | 4 | with 'MooseX::Clone'; | |||||||||
| 14 | |||||||||||
| 15 | has 'component_list' => ( | ||||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | isa => 'Graphics::Primitive::ComponentList', | ||||||||||
| 18 | 6 | ▶ | default => sub { Graphics::Primitive::ComponentList->new }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | handles => [qw(component_count components constraints each find find_component get_component get_constraint)], | ||||||||||
| 20 | 0 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 21 | 4 | ); | |||||||||
| 22 | has 'layout_manager' => ( | ||||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => 'Layout::Manager', | ||||||||||
| 25 | handles => [ 'do_layout' ], | ||||||||||
| 26 | 0 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 4 | ); | |||||||||
| 28 | |||||||||||
| 29 | 13 | ▶ | sub add_component { | ||||||||
|
Subroutine
add_component: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 30 | 13 | my ($self, $component, $args) = @_; | |||||||||
| 31 | |||||||||||
| 32 | 13 | ▶ | return 0 unless $self->validate_component($component, $args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 13 | $component->parent($self); | |||||||||
| 35 | 13 | $self->component_list->add_component($component, $args); | |||||||||
| 36 | |||||||||||
| 37 | 13 | $self->prepared(0); | |||||||||
| 38 | |||||||||||
| 39 | 13 | return 1; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | ▶ | sub clear_components { | ||||||||
|
Subroutine
clear_components: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 43 | 1 | my ($self) = @_; | |||||||||
| 44 | |||||||||||
| 45 | # Clear all the component's parent attributes just in case some | ||||||||||
| 46 | # outside thingie is holding a reference to it | ||||||||||
| 47 | 1 | foreach my $c (@{ $self->components }) { | |||||||||
| 48 | 3 | ▶ | next unless(defined($c)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 2 | $c->parent(undef); | |||||||||
| 50 | } | ||||||||||
| 51 | 1 | $self->component_list->clear; | |||||||||
| 52 | 1 | $self->prepared(0); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub get_tree { | ||||||||
|
Subroutine
get_tree: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 56 | 0 | my ($self) = @_; | |||||||||
| 57 | |||||||||||
| 58 | 0 | my $tree = Forest::Tree->new(node => $self); | |||||||||
| 59 | |||||||||||
| 60 | 0 | foreach my $c (@{ $self->components }) { | |||||||||
| 61 | 0 | $tree->add_child($c->get_tree); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | return $tree; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 2 | ▶ | sub prepare { | ||||||||
|
Subroutine
prepare: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||
| 68 | 2 | my ($self, $driver) = @_; | |||||||||
| 69 | |||||||||||
| 70 | 2 | ▶ | return if $self->prepared; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | |||||||||||
| 72 | 2 | ▶ | unless($self->minimum_width) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 2 | $self->minimum_width($self->outside_width); | |||||||||
| 74 | } | ||||||||||
| 75 | 2 | ▶ | unless($self->minimum_height) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 2 | $self->minimum_height($self->outside_height); | |||||||||
| 77 | } | ||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 1 | ▶ | sub remove_component { | ||||||||
|
Subroutine
remove_component: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 81 | 1 | my ($self, $component) = @_; | |||||||||
| 82 | |||||||||||
| 83 | 1 | my $removed = $self->component_list->remove_component($component); | |||||||||
| 84 | 1 | ▶ | if(scalar(@{ $removed })) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 1 | foreach my $r (@{ $removed }) { | |||||||||
| 86 | 1 | $r->parent(undef); | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | return $removed; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 13 | ▶ | sub validate_component { | ||||||||
|
Subroutine
validate_component: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 94 | 13 | my ($self, $c, $a) = @_; | |||||||||
| 95 | |||||||||||
| 96 | 13 | return 1; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 100 | |||||||||||
| 101 | 4 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 102 | 4 | 1; | |||||||||
| 103 | __END__ | ||||||||||