line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Growl::Any::Base; |
2
|
5
|
|
|
5
|
|
2630
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
250
|
|
3
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
126
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
36
|
use Carp (); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
69
|
|
6
|
5
|
|
|
5
|
|
5615
|
use Encode (); |
|
5
|
|
|
|
|
119594
|
|
|
5
|
|
|
|
|
4479
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
0
|
904
|
sub encoding { 'UTF-8' } # overridable if needed |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
3
|
|
|
3
|
0
|
71
|
my $class = shift; |
12
|
3
|
50
|
|
|
|
29
|
my %args = ( @_ == 1 ? %{$_[0]} : @_); |
|
0
|
|
|
|
|
0
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
13
|
my $self = bless \%args, $class; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
33
|
|
|
42
|
my $e = $args{encoding} || $class->encoding; |
17
|
3
|
|
33
|
|
|
19
|
$self->{encoding} = Encode::find_encoding( $e ) |
18
|
|
|
|
|
|
|
|| Carp::croak("Unknown encoding '$e'"); |
19
|
|
|
|
|
|
|
|
20
|
3
|
50
|
33
|
|
|
917
|
$self->register($args{appname}, $args{events}) |
21
|
|
|
|
|
|
|
if $args{appname} or $args{events}; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
12
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub appname { |
27
|
0
|
|
|
0
|
0
|
0
|
my($self) = @_; |
28
|
0
|
|
|
|
|
0
|
return $self->{appname}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub register { |
32
|
3
|
|
|
3
|
0
|
29
|
my($self, $appname, $events) = @_; |
33
|
3
|
50
|
|
|
|
15
|
Carp::croak("register() is an instance method") if not ref $self; |
34
|
3
|
50
|
|
|
|
13
|
Carp::croak("You must define an app name") if not defined $appname; |
35
|
3
|
50
|
|
|
|
16
|
Carp::croak("You must pass events") if ref($events) ne 'ARRAY'; |
36
|
3
|
|
|
|
|
121
|
$self->{appname} = $self->encode($appname); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# parameters |
40
|
|
|
|
|
|
|
# event |
41
|
|
|
|
|
|
|
# title |
42
|
|
|
|
|
|
|
# message |
43
|
|
|
|
|
|
|
# icon (optional) |
44
|
|
|
|
|
|
|
# link (optional) |
45
|
|
|
|
|
|
|
sub notify; # abstract method |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub encode { |
48
|
3
|
|
|
3
|
0
|
27
|
my($self, $text_str) = @_; |
49
|
3
|
50
|
|
|
|
56
|
return defined($text_str) |
50
|
|
|
|
|
|
|
? $self->{encoding}->encode($text_str) |
51
|
|
|
|
|
|
|
: $text_str; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub encode_from { |
55
|
0
|
|
|
0
|
0
|
0
|
my($self, $from, $text_str) = @_; |
56
|
0
|
0
|
|
|
|
0
|
if (defined($text_str)) { |
57
|
0
|
|
|
|
|
0
|
Encode::from_to($text_str, $from, $self->{encoding}->name); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
0
|
$text_str; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub encode_list { |
63
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
64
|
2
|
50
|
|
|
|
6
|
return map { defined($_) ? $self->{encoding}->encode($_) : $_ } @_; |
|
4
|
|
|
|
|
566
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub encode_list_from { |
68
|
0
|
|
|
0
|
0
|
|
my ($self, $from) = @_; |
69
|
0
|
0
|
|
|
|
|
return map { |
70
|
0
|
|
|
|
|
|
Encode::from_to($_, $from, $self->{encoding}->name) if defined($_); |
71
|
0
|
|
|
|
|
|
$_ |
72
|
|
|
|
|
|
|
} @_; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _tmpfile { # returns a filehandle with filename() method |
76
|
0
|
|
|
0
|
|
|
my($self, $suffix) = @_; |
77
|
0
|
|
|
|
|
|
require File::Temp; |
78
|
0
|
|
|
|
|
|
my (undef, $filename) = File::Temp::tempfile( SUFFIX => $suffix, CLEANUP => 1, OPEN => 0 ); |
79
|
0
|
|
|
|
|
|
return $filename; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _ua { |
83
|
0
|
|
|
0
|
|
|
my($self) = @_; |
84
|
0
|
|
0
|
|
|
|
return $self->{ua} ||= do { |
85
|
0
|
|
|
|
|
|
require LWP; |
86
|
0
|
|
|
|
|
|
require LWP::UserAgent; |
87
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( agent => |
88
|
|
|
|
|
|
|
sprintf 'Growl::Any (LWP/%s)', LWP->VERSION ); |
89
|
0
|
|
|
|
|
|
$ua->env_proxy(); |
90
|
0
|
|
|
|
|
|
$ua->timeout(10); |
91
|
0
|
|
|
|
|
|
return $ua; |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub icon_file { |
96
|
0
|
|
|
0
|
0
|
|
my($self, $icon) = @_; |
97
|
0
|
0
|
|
|
|
|
unless(-e $icon) { # seems URI |
98
|
0
|
|
|
|
|
|
my $ext = $icon; |
99
|
0
|
|
|
|
|
|
$ext =~ s/#.*$//; |
100
|
0
|
0
|
|
|
|
|
$ext = $ext =~ /.*(\.[a-zA-Z0-9]+)$/ ? $1 : ''; |
101
|
0
|
|
|
|
|
|
my $tmpfile = $self->_tmpfile( $ext ); |
102
|
0
|
|
|
|
|
|
my $res = $self->_ua->mirror( $icon, $tmpfile ); |
103
|
0
|
0
|
|
|
|
|
return $tmpfile if $res->is_success; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
return $icon; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |