line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Duadua::CLI; |
2
|
2
|
|
|
2
|
|
129245
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
56
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
362
|
use Duadua; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
5
|
2
|
|
|
2
|
|
1640
|
use Getopt::Long qw/GetOptionsFromArray/; |
|
2
|
|
|
|
|
22183
|
|
|
2
|
|
|
|
|
7
|
|
6
|
2
|
|
|
2
|
|
1209
|
use JSON qw/encode_json/; |
|
2
|
|
|
|
|
9039
|
|
|
2
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
3
|
|
|
3
|
1
|
598018
|
my $class = shift; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
|
|
77
|
return bless { |
12
|
|
|
|
|
|
|
_d => Duadua->new('', { version => 1 }), |
13
|
|
|
|
|
|
|
_opt => $class->_get_opt(@_), |
14
|
|
|
|
|
|
|
}, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
1
|
825
|
sub d { shift->{_d} } |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
1
|
64
|
sub opt { $_[0]->{_opt}{$_[1]} } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub run { |
22
|
2
|
|
|
2
|
1
|
4144
|
my ($self) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
12
|
my @results; |
25
|
|
|
|
|
|
|
|
26
|
2
|
100
|
|
|
|
10
|
if (my $ua_list = $self->opt('ua_list')) { |
27
|
1
|
|
|
|
|
4
|
for my $ua (@{$ua_list}) { |
|
1
|
|
|
|
|
25
|
|
28
|
1
|
|
|
|
|
10
|
push @results, $self->_parse($ua); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
2
|
100
|
|
|
|
9
|
if ($self->_is_opened_stdin) { |
33
|
1
|
|
|
|
|
19
|
while (my $ua = ) { |
34
|
1
|
|
|
|
|
7
|
chomp $ua; |
35
|
1
|
|
|
|
|
3
|
push @results, $self->_parse($ua); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
|
|
|
8
|
if (scalar @results == 0) { |
40
|
0
|
|
|
|
|
0
|
_show_usage(1); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
2
|
50
|
|
|
|
176
|
print encode_json(scalar @results == 1 ? $results[0] : \@results); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
12
|
sub _is_opened_stdin { -p STDIN } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _parse { |
50
|
2
|
|
|
2
|
|
9
|
my ($self, $ua) = @_; |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
12
|
$ua =~ s!^"!!g; |
53
|
2
|
|
|
|
|
15
|
$ua =~ s!"$!!g; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
9
|
my $r = $self->d->reparse($ua); |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
100
|
|
|
9
|
my $v = { |
58
|
|
|
|
|
|
|
ua => $r->ua, |
59
|
|
|
|
|
|
|
name => $r->name, |
60
|
|
|
|
|
|
|
version => $r->version || '-', |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
13
|
for my $k (qw/ |
64
|
|
|
|
|
|
|
is_bot |
65
|
|
|
|
|
|
|
is_ios |
66
|
|
|
|
|
|
|
is_android |
67
|
|
|
|
|
|
|
is_linux |
68
|
|
|
|
|
|
|
is_windows |
69
|
|
|
|
|
|
|
is_chromeos |
70
|
|
|
|
|
|
|
/) { |
71
|
12
|
|
100
|
|
|
46
|
$v->{$k} = $r->$k || 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
13
|
return $v; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _get_opt { |
78
|
3
|
|
|
3
|
|
25
|
my ($class, @argv) = @_; |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
9
|
my $opt = {}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
GetOptionsFromArray( |
83
|
|
|
|
|
|
|
\@argv, |
84
|
|
|
|
|
|
|
'help' => sub { |
85
|
0
|
|
|
0
|
|
0
|
$class->_show_usage(1); |
86
|
|
|
|
|
|
|
}, |
87
|
|
|
|
|
|
|
'version' => sub { |
88
|
0
|
|
|
0
|
|
0
|
print "$0 $Duadua::VERSION\n"; |
89
|
0
|
|
|
|
|
0
|
exit 1; |
90
|
|
|
|
|
|
|
}, |
91
|
3
|
|
|
|
|
99
|
); |
92
|
|
|
|
|
|
|
|
93
|
3
|
100
|
|
|
|
1171
|
if (scalar @argv > 0) { |
94
|
2
|
|
|
|
|
5
|
push @{$opt->{ua_list}}, @argv; |
|
2
|
|
|
|
|
24
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
41
|
return $opt; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _show_usage { |
101
|
1
|
|
|
1
|
|
131
|
my ($class, $exitval) = @_; |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
576
|
require Pod::Usage; |
104
|
1
|
|
|
|
|
55930
|
Pod::Usage::pod2usage(-exitval => $exitval); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |