| 1 | package Growl::Any::Base; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | sub encoding { 'UTF-8' } # overridable if needed | ||||||||||||||||||||||||||
|
Subroutine
encoding: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 12 | 0 | ▶ | my %args = ( @_ == 1 ? %{$_[0]} : @_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | my $self = bless \%args, $class; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | my $e = $args{encoding} || $class->encoding; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{'encoding'} || $class->encoding
MC/DC0%0/2
$args{'encoding'} || $class->encoding
$args{'encoding'}
$class->encoding
Truth table33%1/3
A || B
A= $args{'encoding'}B= $class->encoding
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | $self->{encoding} = Encode::find_encoding( $e ) | ||||||||||||||||||||||||||
|
Condition50%1/2
&Encode::find_encoding($e) || Carp::croak("Unknown encoding '${e}'")
MC/DC0%0/1
&Encode::find_encoding($e) || Carp::croak("Unknown encoding '${e}'")
&Encode::find_encoding($e)
Truth table50%1/2
A
A= &Encode::find_encoding($e)
| |||||||||||||||||||||||||||||
| 18 | || Carp::croak("Unknown encoding '$e'"); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | $self->register($args{appname}, $args{events}) | ||||||||||||||||||||||||||||
| 21 | 3 | ▶ | if $args{appname} or $args{events}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"appname"} or $args{"events"}
MC/DC0%0/2
$args{"appname"} or $args{"events"}
$args{"appname"}
$args{"events"}
Truth table33%1/3
A or B
A= $args{"appname"}B= $args{"events"}
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | return $self; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub appname { | ||||||||||||||||||||||||||
|
Subroutine
appname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 28 | 0 | return $self->{appname}; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 3 | my($self, $appname, $events) = @_; | |||||||||||||||||||||||||||
| 33 | 3 | ▶ | Carp::croak("register() is an instance method") if not ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | Carp::croak("You must define an app name") if not defined $appname; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | Carp::croak("You must pass events") if ref($events) ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 3 | $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 | 3 | ▶ | sub encode { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 3 | my($self, $text_str) = @_; | |||||||||||||||||||||||||||
| 49 | return defined($text_str) | ||||||||||||||||||||||||||||
| 50 | 3 | ▶ | ? $self->{encoding}->encode($text_str) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | : $text_str; | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub encode_from { | ||||||||||||||||||||||||||
|
Subroutine
encode_from: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my($self, $from, $text_str) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (defined($text_str)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | Encode::from_to($text_str, $from, $self->{encoding}->name); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | $text_str; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub encode_list { | ||||||||||||||||||||||||||
|
Subroutine
encode_list: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | return map { defined($_) ? $self->{encoding}->encode($_) : $_ } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub encode_list_from { | ||||||||||||||||||||||||||
|
Subroutine
encode_list_from: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 0 | my ($self, $from) = @_; | |||||||||||||||||||||||||||
| 69 | return map { | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | Encode::from_to($_, $from, $self->{encoding}->name) if defined($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $_ | |||||||||||||||||||||||||||
| 72 | } @_; | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub _tmpfile { # returns a filehandle with filename() method | ||||||||||||||||||||||||||
|
Subroutine
_tmpfile: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 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 | 0 | ▶ | sub _ua { | ||||||||||||||||||||||||||
|
Subroutine
_ua: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 83 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | return $self->{ua} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"ua"} ||= do {
require LWP;
require LWP::UserAgent;
my $ua = "LWP::UserAgent"->new("agent", sprintf("Growl::Any (LWP/%s)", "LWP"->VERSION));
$ua->env_proxy;
$ua->timeout(10);
return $ua
}
MC/DC0%0/2
$self->{"ua"} ||= do {
require LWP;
require LWP::UserAgent;
my $ua = "LWP::UserAgent"->new("agent", sprintf("Growl::Any (LWP/%s)", "LWP"->VERSION));
$ua->env_proxy;
$ua->timeout(10);
return $ua
}
$self->{"ua"}
do {
require LWP;
require LWP::UserAgent;
my $ua = "LWP::UserAgent"->new("agent", sprintf("Growl::Any (LWP/%s)", "LWP"->VERSION));
$ua->env_proxy;
$ua->timeout(10);
return $ua
}
Truth table0%0/3
A ||= B
A= $self->{"ua"}B= do {
require LWP;
require LWP::UserAgent;
my $ua = "LWP::UserAgent"->new("agent", sprintf("Growl::Any (LWP/%s)", "LWP"->VERSION));
$ua->env_proxy;
$ua->timeout(10);
return $ua
}
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub icon_file { | ||||||||||||||||||||||||||
|
Subroutine
icon_file: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 0 | my($self, $icon) = @_; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | unless(-e $icon) { # seems URI | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my $ext = $icon; | |||||||||||||||||||||||||||
| 99 | 0 | $ext =~ s/#.*$//; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | $ext = $ext =~ /.*(\.[a-zA-Z0-9]+)$/ ? $1 : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | my $tmpfile = $self->_tmpfile( $ext ); | |||||||||||||||||||||||||||
| 102 | 0 | my $res = $self->_ua->mirror( $icon, $tmpfile ); | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $tmpfile if $res->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | return $icon; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 5 | 1; | |||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||