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