Plugin/Image.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 49 / 49 CC 6 SCAR 12.0
CC
6
Cov
100%
image
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
« Plugin/Multiselect.pm ↑ Summary Plugin/Textarea.pm »
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package HTML::Widget::Plugin::Image;
4 # ABSTRACT: an image object
5 15 $HTML::Widget::Plugin::Image::VERSION = '0.204';
6 15 ▶use parent 'HTML::Widget::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 SYNOPSIS
9 #pod
10 #pod $widget_factory->image({
11 #pod src => 'http://example.com/example.jpg',
12 #pod alt => 'An Example Image',
13 #pod });
14 #pod
15 #pod =head1 DESCRIPTION
16 #pod
17 #pod This plugin provides a basic image widget.
18 #pod
19 #pod =cut
20  
21 15 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 15 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 #pod =head1 METHODS
25 #pod
26 #pod =head2 C< provided_widgets >
27 #pod
28 #pod This plugin provides the following widgets: image
29 #pod
30 #pod =cut
31  
32 16 ▶sub provided_widgets { qw(image) }
Subroutine provided_widgets: called CC=1 SCAR=0.0
Pod documented
33  
34 #pod =head2 C< image >
35 #pod
36 #pod This method returns a basic image element.
37 #pod
38 #pod In addition to the generic L<HTML::Widget::Plugin> attributes, the following
39 #pod are valid arguments:
40 #pod
41 #pod =over
42 #pod
43 #pod =item src
44 #pod
45 #pod This is the source href for the image. "href" is a synonym for src. If no
46 #pod href is supplied, an exception is thrown.
47 #pod
48 #pod =item alt
49 #pod
50 #pod This is the alt text for the image.
51 #pod
52 #pod =back
53 #pod
54 #pod =cut
55  
56 16 ▶sub _attribute_args { qw(src alt) }
Subroutine _attribute_args: called CC=1 SCAR=0.0
57  
58 4 ▶sub image {
Subroutine image: called CC=6 SCAR=17.9
Pod documented
59 4 my ($self, $factory, $arg) = @_;
60  
61 4 ▶ if ($arg->{attr}{src} and $arg->{href}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"attr"}{"src"} and $arg->{"href"}) 1 3 4
Condition100%3/3
$arg->{"attr"}{"src"} and $arg->{"href"}
!ll&&!rl&&r
211
MC/DC100%2/2
$arg->{"attr"}{"src"} and $arg->{"href"}
$arg->{"attr"}{"src"} $arg->{"href"}
Truth table100%3/3
A and B
A= $arg->{"attr"}{"src"}B= $arg->{"href"}
ABresult
0X0
100
111
62 1 Carp::croak "don't provide both href and src for image widget";
63 }
64  
65 3 ▶ $arg->{attr}{src} = $arg->{href} if not defined $arg->{attr}{src};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg->{"attr"}{"src"} 2 1 3
66  
67 Carp::croak "can't create an image without a src"
68 3 ▶ unless defined $arg->{attr}{src};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg->{"attr"}{"src"} 1 2 3
69  
70 2 my $widget = HTML::Element->new('img');
71 2 $widget->attr($_ => $arg->{attr}{$_}) for keys %{ $arg->{attr} };
72  
73 2 return $widget->as_XML;
74 }
75  
76 15 1;
77  
78 __END__
« Plugin/Multiselect.pm ↑ Summary Plugin/Textarea.pm »