line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UseCase::Host; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use List::Util qw(max); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
271
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Storage |
9
|
|
|
|
|
|
|
my %HOSTS = ( |
10
|
|
|
|
|
|
|
1 => { |
11
|
|
|
|
|
|
|
name => 'deathstart.com', |
12
|
|
|
|
|
|
|
user_id => 1, |
13
|
|
|
|
|
|
|
state => 'active', |
14
|
|
|
|
|
|
|
}, |
15
|
|
|
|
|
|
|
2 => { |
16
|
|
|
|
|
|
|
name => 'jedi.com', |
17
|
|
|
|
|
|
|
user_id => 2, |
18
|
|
|
|
|
|
|
state => 'active', |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
3 => { |
21
|
|
|
|
|
|
|
name => 'naboo.com', |
22
|
|
|
|
|
|
|
user_id => 2, |
23
|
|
|
|
|
|
|
state => 'inactive', |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub list { |
28
|
2
|
|
|
2
|
0
|
7
|
my %params = @_; |
29
|
2
|
|
|
|
|
10
|
map { { id => $_, %{ $HOSTS{$_} } } } sort { $a <=> $b } keys %HOSTS; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
28
|
|
|
6
|
|
|
|
|
13
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub create { |
33
|
2
|
|
|
2
|
0
|
7
|
my %params = @_; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
14
|
my $id = max(keys %HOSTS) + 1; |
36
|
2
|
|
|
|
|
6
|
$HOSTS{$id} = \%params; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
9
|
$id; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub show { |
42
|
1
|
|
|
1
|
0
|
3
|
my $id = shift; |
43
|
1
|
|
|
|
|
3
|
$HOSTS{$id}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub edit { |
47
|
2
|
|
|
2
|
0
|
8
|
my ($id, %params) = @_; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
6
|
foreach my $p (keys %params) { |
50
|
4
|
50
|
|
|
|
8
|
next unless $params{$p}; |
51
|
4
|
|
|
|
|
9
|
$HOSTS{$id}{$p} = $params{$p}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
8
|
$HOSTS{$id}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub remove { |
58
|
1
|
|
|
1
|
0
|
3
|
my $id = shift; |
59
|
1
|
|
|
|
|
4
|
delete $HOSTS{$id}; |
60
|
1
|
|
|
|
|
4
|
1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |