blib/lib/Rose/HTML/Image.pm

filter: Statementstmt 79.7% 55 / 69 Branchbran 55.5% 10 / 18 Conditioncond 31.2% 5 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 83.3% 15 / 18 Podpod 88.8% 8 / 9 totaltotal 66.9% 93 / 139 CC 16 SCAR 10.7
CC
16
Cov
68%
path
6.0
_new_path
6.0
init_size
3.6
CRAP 2.9
« blib/lib/Rose/HTML/Object/Messages.pm ↑ Summary blib/lib/Rose/HTML/Object/WithWrapAroundChildren.pm »
1 package Rose::HTML::Image;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Image::Size;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use base 'Rose::HTML::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $DOC_ROOT;
10  
11 3 our $VERSION = '0.606';
12  
13 3 __PACKAGE__->add_required_html_attrs(
14 {
15 'alt', => '',
16 'src', => '',
17 });
18  
19  
20 3 __PACKAGE__->add_valid_html_attrs
21 (
22 'src', # %URI; #REQUIRED -- URI of image to embed --
23 'alt', # %Text; #REQUIRED -- short description --
24 'longdesc', # %URI; #IMPLIED -- link to long description --
25 'name', # CDATA #IMPLIED -- name of image for scripting --
26 'height', # %Length; #IMPLIED -- override height --
27 'width', # %Length; #IMPLIED -- override width --
28 'usemap', # %URI; #IMPLIED -- use client-side image map --
29 'ismap', # (ismap) #IMPLIED -- use server-side image map --
30 );
31  
32 3 __PACKAGE__->add_boolean_html_attrs
33 (
34 'ismap',
35 );
36  
37 12 ▶sub is_self_closing { 1 }
Subroutine is_self_closing: called CC=1 SCAR=0.0
Pod documented
38  
39 0 ▶sub element { 'img' }
Subroutine element: not called CC=1 SCAR=6.9
Pod documented
40 6 ▶sub html_element { 'img' }
Subroutine html_element: called CC=1 SCAR=0.0
Pod documented
41 6 ▶sub xhtml_element { 'img' }
Subroutine xhtml_element: called CC=1 SCAR=0.0
Pod documented
42  
43 QUIET:
44 {
45 3 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
46 3 ▶ use constant MOD_PERL_1 => ($ENV{'MOD_PERL'} && !$ENV{'MOD_PERL_API_VERSION'}) ? 1 : 0;
Subroutine BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MOD_PERL'} && !$ENV{'MOD_PERL_API_VERSION'} ? : 0 3 3
Condition33%1/3
$ENV{"MOD_PERL"} and not $ENV{"MOD_PERL_API_VERSION"}
!ll&&!rl&&r
300
MC/DC0%0/2
$ENV{"MOD_PERL"} and not $ENV{"MOD_PERL_API_VERSION"}
$ENV{"MOD_PERL"} not $ENV{"MOD_PERL_API_VERSION"}
Truth table33%1/3
A and not(B)
A= $ENV{"MOD_PERL"}B= not $ENV{"MOD_PERL_API_VERSION"}
ABresult
0X0
100
111
47 3 ▶ use constant MOD_PERL_2 => ($ENV{'MOD_PERL'} && $ENV{'MOD_PERL_API_VERSION'} == 2) ? 1 : 0;
Subroutine BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MOD_PERL'} && $ENV{'MOD_PERL_API_VERSION'} == 2 ? : 0 3 3
Condition33%1/3
$ENV{"MOD_PERL"} and $ENV{"MOD_PERL_API_VERSION"} == 2
!ll&&!rl&&r
300
MC/DC0%0/2
$ENV{"MOD_PERL"} and $ENV{"MOD_PERL_API_VERSION"} == 2
$ENV{"MOD_PERL"} $ENV{"MOD_PERL_API_VERSION"} == 2
Truth table33%1/3
A and B
A= $ENV{"MOD_PERL"}B= $ENV{"MOD_PERL_API_VERSION"} == 2
ABresult
0X0
100
111
48  
49 3 ▶ use constant TRY_MOD_PERL_2 => eval { require Apache2::RequestUtil } && !$@ ? 1 : 0;
Subroutine BEGIN: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Apache2::RequestUtil } } && !$@ ? : 0 3 3
Condition33%1/3
eval { do { require Apache2::RequestUtil } } and not $@
!ll&&!rl&&r
300
MC/DC0%0/2
eval { do { require Apache2::RequestUtil } } and not $@
eval { do { require Apache2::RequestUtil } } not $@
Truth table33%1/3
A and not(B)
A= eval { do { require Apache2::RequestUtil } }B= not $@
ABresult
0X0
100
111
50 }
51  
52 sub init_document_root
53 3 ▶{
Subroutine init_document_root: called CC=2 SCAR=7.0
Pod undocumented
54 4 if(MOD_PERL_1)
55 {
56 return Apache->request->document_root;
57 }
58  
59 4 if(TRY_MOD_PERL_2)
60 {
61 my $r;
62  
63 TRY:
64 {
65 local $@;
66 eval { $r = Apache2::RequestUtil->request };
67 }
68  
69 if($r)
70 {
71 return $r->document_root;
72 }
73 }
74  
75 4 ▶ return $DOC_ROOT || '';
Condition50%1/2
$Rose::HTML::Image::DOC_ROOT || ''
l!l
04
MC/DC0%0/1
$Rose::HTML::Image::DOC_ROOT || ''
$Rose::HTML::Image::DOC_ROOT
Truth table50%1/2
A
A= $Rose::HTML::Image::DOC_ROOT
Aresult
11
00
76 }
77  
78 sub src
79 8 ▶{
Subroutine src: called CC=2 SCAR=6.9
Pod documented
80 8 my($self) = shift;
81 8 my $src = $self->html_attr('src', @_);
82 8 ▶ $self->_new_src_or_document_root($src) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 3 8
83 8 return $src;
84 }
85  
86 sub path
87 0 ▶{
Subroutine path: not called CC=2 SCAR=17.9
Pod documented
88 0 my($self) = shift;
89 0 ▶ return $self->{'path'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
90 0 $self->_new_path($self->{'path'} = shift);
91 0 return $self->{'path'};
92 }
93  
94 sub document_root
95 11 ▶{
Subroutine document_root: called CC=3 SCAR=11.0
Pod documented
96 11 my($self) = shift;
97  
98 11 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 8 11
99 {
100 3 $self->{'document_root'} = shift;
101 3 $self->_new_src_or_document_root($self->src);
102 3 return $self->{'document_root'};
103 }
104  
105 $self->{'document_root'} = $self->init_document_root
106 8 ▶ unless(defined $self->{'document_root'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"document_root"} 4 4 8
107  
108 8 return $self->{'document_root'};
109 }
110  
111 sub _new_src_or_document_root
112 8 ▶{
Subroutine _new_src_or_document_root: called CC=2 SCAR=7.4
113 8 my($self, $src) = @_;
114  
115 8 ▶ if(-e $src)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $src) { } 0 8 8
116 {
117 0 $self->{'path'} = $src;
118 }
119 else
120 {
121 8 $self->{'path'} = $self->document_root . $src;
122 }
123  
124 8 $self->init_size($self->{'path'});
125 }
126  
127 sub _new_path
128 0 ▶{
Subroutine _new_path: not called CC=2 SCAR=17.9
129 0 my($self, $path) = @_;
130  
131 0 ▶ unless($self->{'document_root'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"document_root"}) 0 0 0
132 {
133 0 $self->init_size;
134 0 return;
135 }
136  
137 0 my $src = $path;
138  
139 0 $src =~ s/^$self->{'document_root'}//;
140  
141 0 $self->html_attr('src' => $src);
142  
143 0 $self->init_size;
144 }
145  
146 sub init_size
147 8 ▶{
Subroutine init_size: called CC=3 SCAR=12.7
Pod documented
148 8 my($self, $path) = @_;
149  
150 8 ▶ $path ||= $self->{'path'} || return;
Condition20%1/5
$path ||= $self->{"path"} || (return)
l!l&&r!l&&!r
800
$self->{'path'} || (return)
l!l
00
MC/DC0%0/2
$path ||= $self->{"path"} || (return)
$path $self->{'path'}
Truth table33%1/3
A ||= B
A= $pathB= $self->{'path'}
ABresult
1X1
011
000
151  
152 8 my($w, $h) = Image::Size::imgsize($path);
153  
154 8 $self->html_attr(width => $w);
155 8 $self->html_attr(height => $h);
156 }
157  
158 3 1;
159  
160 __END__
« blib/lib/Rose/HTML/Object/Messages.pm ↑ Summary blib/lib/Rose/HTML/Object/WithWrapAroundChildren.pm »