| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::HtmlKitCom::FavIconFromImage; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
271789
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
56
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
80
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use WWW::Mechanize; |
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
25
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Devel::TakeHashArgs; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
77
|
|
|
11
|
1
|
|
|
1
|
|
7
|
use base 'Class::Accessor::Grouped'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
724
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_group_accessors( simple => qw( |
|
14
|
|
|
|
|
|
|
error |
|
15
|
|
|
|
|
|
|
mech |
|
16
|
|
|
|
|
|
|
response |
|
17
|
|
|
|
|
|
|
)); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
1
|
|
|
1
|
1
|
282
|
my $self = bless {}, shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
12
|
get_args_as_hash( \@_, \ my %args, { timeout => 180 } ) |
|
24
|
|
|
|
|
|
|
or croak $@; |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
33
|
|
|
52
|
$args{mech} ||= WWW::Mechanize->new( |
|
27
|
|
|
|
|
|
|
timeout => $args{timeout}, |
|
28
|
|
|
|
|
|
|
agent => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12)' |
|
29
|
|
|
|
|
|
|
.' Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12', |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
25685
|
$self->mech( $args{mech} ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
318
|
return $self; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub favicon { |
|
38
|
1
|
|
|
1
|
1
|
1280
|
my $self = shift; |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
8
|
$self->$_(undef) for qw(error response); |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
401
|
my $image = shift; |
|
43
|
1
|
50
|
|
|
|
11
|
get_args_as_hash( \@_, \ my %args, { # also used: `file` |
|
44
|
|
|
|
|
|
|
image => $image, |
|
45
|
|
|
|
|
|
|
}, |
|
46
|
|
|
|
|
|
|
) or croak $@; |
|
47
|
|
|
|
|
|
|
|
|
48
|
1
|
50
|
|
|
|
57
|
-e $args{image} |
|
49
|
|
|
|
|
|
|
or return $self->_set_error("File `$args{image}` does not exist"); |
|
50
|
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
6
|
my $mech = $self->mech; |
|
52
|
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
8
|
$mech->get('http://www.html-kit.com/favicon/')->is_success |
|
54
|
|
|
|
|
|
|
or return $self->_set_error( $mech, 'net' ); |
|
55
|
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
815284
|
$mech->form_number(1) |
|
57
|
|
|
|
|
|
|
or return $self->_set_error('Failed to find favicon form'); |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
18382
|
$mech->set_visible( |
|
60
|
|
|
|
|
|
|
$args{image}, |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
48
|
$mech->click->is_success |
|
64
|
|
|
|
|
|
|
or return $self->_set_error( $mech, 'net' ); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# use Data::Dumper; |
|
67
|
|
|
|
|
|
|
# print $mech->res->decoded_content; |
|
68
|
|
|
|
|
|
|
# exit; |
|
69
|
1
|
50
|
|
|
|
19924751
|
my $response = $mech->follow_link( |
|
70
|
|
|
|
|
|
|
url_regex => qr|^\Qhttp://favicon.htmlkit.com/favicon/download/| |
|
71
|
|
|
|
|
|
|
) or return $self->_set_error( |
|
72
|
|
|
|
|
|
|
'Failed to create favicon. Check your args' |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
50
|
|
|
|
214395
|
$response->is_success |
|
76
|
|
|
|
|
|
|
or return $self->_set_error( $mech, 'net' ); |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
14
|
if ( $args{file} ) { |
|
79
|
0
|
0
|
|
|
|
0
|
open my $fh, '>', $args{file} |
|
80
|
|
|
|
|
|
|
or return $self->_set_error( |
|
81
|
|
|
|
|
|
|
"Failed to open `$args{file}` for writing ($!)" |
|
82
|
|
|
|
|
|
|
); |
|
83
|
0
|
|
|
|
|
0
|
binmode $fh; |
|
84
|
0
|
|
|
|
|
0
|
print $fh $response->content; |
|
85
|
0
|
|
|
|
|
0
|
close $fh; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
1
|
|
|
|
|
11
|
return $self->response($response); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _set_error { |
|
91
|
0
|
|
|
0
|
|
|
my ( $self, $mech_or_message, $type ) = @_; |
|
92
|
0
|
0
|
|
|
|
|
if ( $type ) { |
|
93
|
0
|
|
|
|
|
|
$self->error( |
|
94
|
|
|
|
|
|
|
'Network error: ' . $mech_or_message->res->status_line |
|
95
|
|
|
|
|
|
|
); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
else { |
|
98
|
0
|
|
|
|
|
|
$self->error( $mech_or_message ); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
return; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
|
105
|
|
|
|
|
|
|
__END__ |