line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UseCase::Host; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use List::Util qw(max); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
341
|
|
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
|
9
|
my %params = @_; |
29
|
2
|
|
|
|
|
13
|
map { { id => $_, %{ $HOSTS{$_} } } } sort { $a <=> $b } keys %HOSTS; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
32
|
|
|
6
|
|
|
|
|
17
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub create { |
33
|
1
|
|
|
1
|
0
|
6
|
my %params = @_; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
10
|
my $id = max(keys %HOSTS) + 1; |
36
|
1
|
|
|
|
|
4
|
$HOSTS{$id} = \%params; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
5
|
$id; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub show { |
42
|
1
|
|
|
1
|
0
|
3
|
my $id = shift; |
43
|
1
|
|
|
|
|
4
|
$HOSTS{$id}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub edit { |
47
|
2
|
|
|
2
|
0
|
10
|
my ($id, %params) = @_; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
7
|
foreach my $p (keys %params) { |
50
|
4
|
50
|
|
|
|
11
|
next unless $params{$p}; |
51
|
4
|
|
|
|
|
9
|
$HOSTS{$id}{$p} = $params{$p}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
9
|
$HOSTS{$id}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub remove { |
58
|
1
|
|
|
1
|
0
|
2
|
my $id = shift; |
59
|
1
|
|
|
|
|
6
|
delete $HOSTS{$id}; |
60
|
1
|
|
|
|
|
5
|
1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |