Any/Base.pm

filter: Statementstmt 49.2% 31 / 63 Branchbran 29.1% 7 / 24 Conditioncond 27.2% 3 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 60.0% 9 / 15 Podpod 0.0% 0 / 9 totaltotal 38.7% 50 / 129 CC 17 SCAR 18.7
CC
17
Cov
42%
icon_file
20.0
new
8.3
encode_from
6.0
CRAP 6.5
« Any/Win32MSAgent.pm ↑ Summary Any/GrowlNotifySend.pm »
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
BranchTrueFalseTotal
@_ == 1 ? : 0 3 3
13  
14 3 my $self = bless \%args, $class;
15  
16 3 ▶ my $e = $args{encoding} || $class->encoding;
Condition33%1/3
$args{'encoding'} || $class->encoding
l!l&&r!l&&!r
030
MC/DC0%0/2
$args{'encoding'} || $class->encoding
$args{'encoding'} $class->encoding
Truth table33%1/3
A || B
A= $args{'encoding'}B= $class->encoding
ABresult
1X1
011
000
17 3 ▶ $self->{encoding} = Encode::find_encoding( $e )
Condition50%1/2
&Encode::find_encoding($e) || Carp::croak("Unknown encoding '${e}'")
l!l
30
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)
Aresult
11
00
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
BranchTrueFalseTotal
if $args{"appname"} or $args{"events"} 3 0 3
Condition33%1/3
$args{"appname"} or $args{"events"}
l!l&&r!l&&!r
300
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"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless ref $self 0 3 3
34 3 ▶ Carp::croak("You must define an app name") if not defined $appname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $appname 0 3 3
35 3 ▶ Carp::croak("You must pass events") if ref($events) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $events ne "ARRAY" 0 3 3
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
BranchTrueFalseTotal
defined $text_str ? : 3 0 3
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
BranchTrueFalseTotal
if (defined $text_str) 0 0 0
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
BranchTrueFalseTotal
defined $_ ? : 4 0 4
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
BranchTrueFalseTotal
if defined $_ 0 0 0
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 }
l!l&&r!l&&!r
000
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 }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless (-e $icon) 0 0 0
98 0 my $ext = $icon;
99 0 $ext =~ s/#.*$//;
100 0 ▶ $ext = $ext =~ /.*(\.[a-zA-Z0-9]+)$/ ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$ext =~ /.*(\.[a-zA-Z0-9]+)$/ ? : 0 0 0
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
BranchTrueFalseTotal
if $res->is_success 0 0 0
104 }
105 0 return $icon;
106 }
107  
108 5 1;
109 __END__
« Any/Win32MSAgent.pm ↑ Summary Any/GrowlNotifySend.pm »