| 1 | package Marathon::Group; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use parent 'Marathon::Remote'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 2 | my ($class, $conf, $parent) = @_; | |||||||||||||||||||||||||||
| 10 | 2 | my $self = bless {}; | |||||||||||||||||||||||||||
| 11 | 2 | ▶ | $conf = {} unless $conf && ref $conf eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$conf and ref $conf eq "HASH"
MC/DC0%0/2
$conf and ref $conf eq "HASH"
$conf
ref $conf eq "HASH"
Truth table33%1/3
A and B
A= $confB= ref $conf eq "HASH"
| |||||||||||||||||||||||||||||
| 12 | 2 | $self->{data} = $conf; | |||||||||||||||||||||||||||
| 13 | 2 | $self->{parent} = $parent; | |||||||||||||||||||||||||||
| 14 | $self->{children} = { | ||||||||||||||||||||||||||||
| 15 | 2 | apps => {}, | |||||||||||||||||||||||||||
| 16 | groups => {}, | ||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||
| 18 | 2 | ▶ | if ( $conf->{apps} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | foreach ( @{$conf->{apps}} ) { | |||||||||||||||||||||||||||
| 20 | 0 | $self->add( Marathon::App->new( $_, $parent ) ); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 2 | ▶ | if ( $conf->{groups} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | foreach ( @{$conf->{groups}} ) { | |||||||||||||||||||||||||||
| 25 | 0 | $self->add( Marathon::Group->new( $_, $parent ) ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 2 | return $self; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self, $id, $parent) = @_; | |||||||||||||||||||||||||||
| 38 | 0 | my $api_response_obj = $parent->_get_obj('/v2/groups/' . $id); | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | return undef unless $api_response_obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | return $self->new( $api_response_obj, $parent ); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | $self->_bail unless defined $self->{parent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my $response = $self->{parent}->_post('/v2/groups', $self->get_updateable_values); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( $response ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $self->version( decode_json($response)->{version} ); | |||||||||||||||||||||||||||
| 49 | 0 | return $self; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | return undef; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | $self->_bail unless defined $self->{parent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | my $payload = $self->get_updateable_values; | |||||||||||||||||||||||||||
| 58 | 0 | delete $payload->{id}; | |||||||||||||||||||||||||||
| 59 | 0 | my $response = $self->{parent}->_put('/v2/groups/' . $self->id . $self->_uri_args($args), $payload); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( $response ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $self->version( decode_json($response)->{version} ); | |||||||||||||||||||||||||||
| 62 | 0 | return $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | return undef; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | $self->_bail unless defined $self->{parent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | return $self->{parent}->_delete('/v2/groups/' . $self->id . $self->_uri_args($args)); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _uri_args { | ||||||||||||||||||||||||||
|
Subroutine
_uri_args: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 75 | 0 | my $retval = ''; | |||||||||||||||||||||||||||
| 76 | 0 | foreach ( keys %{$args} ) { | |||||||||||||||||||||||||||
| 77 | 0 | $retval .= $_ .'=' . $args->{$_}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return $retval ? '?' . $retval : $retval; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 6 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | 6 | my ($self, $child) = @_; | |||||||||||||||||||||||||||
| 84 | 6 | ▶ | if ( $child->isa('Marathon::App') ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 85 | 3 | ▶ | if ( exists $self->{children}->{apps}->{$child->id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | print STDERR "You cannot add the same App twice.\n" if $Marathon::verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 1 | return 0; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 2 | $self->{children}->{apps}->{$child->id} = $child; | |||||||||||||||||||||||||||
| 90 | } elsif ( $child->isa('Marathon::Group') ) { | ||||||||||||||||||||||||||||
| 91 | 2 | ▶ | if ( $self->is_or_has($child) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 1 | ▶ | print STDERR "You cannot add a group to itself.\n" if $Marathon::verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 1 | return 0; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 1 | $self->{children}->{groups}->{$child->id} = $child; | |||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | print STDERR "You cannot add something else than an App or a Group to a Group.\n" if $Marathon::verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 1 | return 0; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 3 | return 1; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | ▶ | sub is_or_has { | ||||||||||||||||||||||||||
|
Subroutine
is_or_has: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 2 | my ($self, $other) = @_; | |||||||||||||||||||||||||||
| 105 | 2 | ▶ | if ( $self->id eq $other->id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 1 | return 1; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 1 | foreach my $group ( values %{$self->{children}->{groups}} ) { | |||||||||||||||||||||||||||
| 109 | 0 | return $group->is_or_has($other); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 1 | return 0; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub apps { | ||||||||||||||||||||||||||
|
Subroutine
apps: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 116 | 0 | my @apps = values %{$self->{children}->{apps}}; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | return scalar @apps ? wantarray ? @apps : \@apps : undef; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub groups { | ||||||||||||||||||||||||||
|
Subroutine
groups: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | 0 | my @groups = values %{$self->{children}->{groups}}; | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | return scalar @groups ? wantarray ? @groups : \@groups : undef; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub get_updateable_values { | ||||||||||||||||||||||||||
|
Subroutine
get_updateable_values: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | my $struct = { | |||||||||||||||||||||||||||
| 129 | id => $self->id, | ||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ( $self->dependencies ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | $struct->{dependencies} = $self->dependencies; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ( $self->apps ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | $struct->{apps} = []; | |||||||||||||||||||||||||||
| 136 | 0 | foreach my $app ( $self->apps ) { | |||||||||||||||||||||||||||
| 137 | 0 | push @{$struct->{apps}}, $app->get_updateable_values | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ( $self->groups ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | $struct->{groups} = []; | |||||||||||||||||||||||||||
| 142 | 0 | foreach my $group ( $self->groups ) { | |||||||||||||||||||||||||||
| 143 | 0 | push @{$struct->{groups}}, $group->get_updateable_values | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 0 | return $struct; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | 1; | |||||||||||||||||||||||||||