lib/WWW/Mechanize/Image.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod 100% 10 / 10 totaltotal 92.9% 53 / 57 CC 6 SCAR 10.6
CC
6
Cov
91%
new
6.4
BEGIN
1.0
BEGIN
1.0
CRAP 2.9
« lib/WWW/Mechanize.pm ↑ Summary script/mech-dump »
1 package WWW::Mechanize::Image;
2 # vi:et:sw=4 ts=4
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 WWW::Mechanize::Image - Image object for WWW::Mechanize
10  
11 =head1 SYNOPSIS
12  
13 Image object to encapsulate all the stuff that Mech needs
14  
15 =head1 Constructor
16  
17 =head2 new()
18  
19 Creates and returns a new C<WWW::Mechanize::Image> object.
20  
21 my $image = WWW::Mechanize::Image->new( {
22 url => $url,
23 base => $base,
24 tag => $tag,
25 name => $name, # From the INPUT tag
26 height => $height, # optional
27 width => $width, # optional
28 alt => $alt, # optional
29 } );
30  
31 =cut
32  
33 sub new {
34 7 ▶ my $class = shift;
Subroutine new: called CC=6 SCAR=18.5
Pod documented
35 7 ▶ my $parms = shift || {};
Condition50%1/2
shift() || {}
l!l
70
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
36  
37 7 my $self = bless {}, $class;
38  
39 7 for my $parm ( qw( url base tag height width alt name ) ) {
40 # Check for what we passed in, not whether it's defined
41 49 ▶ $self->{$parm} = $parms->{$parm} if exists $parms->{$parm};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms->{$parm} 49 0 49
42 }
43  
44 # url and tag are always required
45 7 for ( qw( url tag ) ) {
46 14 ▶ exists $self->{$_} or die "WWW::Mechanize::Image->new must have a $_ argument";
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} or die "WWW::Mechanize::Image->new must have a $_ argument" 0 14 14
47 }
48  
49 7 return $self;
50 }
51  
52 =head1 Accessors
53  
54 =head2 $link->url()
55  
56 URL from the link
57  
58 =head2 $link->base()
59  
60 Base URL to which the links are relative.
61  
62 =head2 $link->name()
63  
64 Name for the field from the NAME attribute, if any.
65  
66 =head2 $link->tag()
67  
68 Tag name (either "image" or "input")
69  
70 =head2 $link->height()
71  
72 Image height
73  
74 =head2 $link->width()
75  
76 Image width
77  
78 =head2 $link->alt()
79  
80 ALT attribute from the source tag, if any.
81  
82 =cut
83  
84 9 ▶sub url { return ($_[0])->{url}; }
Subroutine url: called CC=1 SCAR=0.0
Pod documented
85 3 ▶sub base { return ($_[0])->{base}; }
Subroutine base: called CC=1 SCAR=0.0
Pod documented
86 1 ▶sub name { return ($_[0])->{name}; }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
87 7 ▶sub tag { return ($_[0])->{tag}; }
Subroutine tag: called CC=1 SCAR=0.0
Pod documented
88 3 ▶sub height { return ($_[0])->{height}; }
Subroutine height: called CC=1 SCAR=0.0
Pod documented
89 3 ▶sub width { return ($_[0])->{width}; }
Subroutine width: called CC=1 SCAR=0.0
Pod documented
90 7 ▶sub alt { return ($_[0])->{alt}; }
Subroutine alt: called CC=1 SCAR=0.0
Pod documented
91  
92 =head2 $link->URI()
93  
94 Returns the URL as a L<URI::URL> object.
95  
96 =cut
97  
98 sub URI {
99 2 ▶ my $self = shift;
Subroutine URI: called CC=1 SCAR=0.0
Pod documented
100  
101 2 require URI::URL;
102 2 my $URI = URI::URL->new( $self->url, $self->base );
103  
104 2 return $URI;
105 }
106  
107 =head2 $link->url_abs()
108  
109 Returns the URL as an absolute URL string.
110  
111 =cut
112  
113 sub url_abs {
114 1 ▶ my $self = shift;
Subroutine url_abs: called CC=1 SCAR=0.0
Pod documented
115  
116 1 return $self->URI->abs;
117 }
118  
119 =head1 SEE ALSO
120  
121 L<WWW::Mechanize> and L<WWW::Mechanize::Link>
122  
123 =head1 COPYRIGHT & LICENSE
124  
125 Copyright 2004-2010 Andy Lester.
126  
127 This program is free software; you can redistribute it and/or modify
128 it under the terms of either:
129  
130 =over 4
131  
132 =item * the GNU General Public License as published by the Free
133 Software Foundation; either version 1, or (at your option) any later
134 version, or
135  
136 =item * the Artistic License version 2.0.
137  
138 =back
139  
140 =cut
141  
142 4 1;
« lib/WWW/Mechanize.pm ↑ Summary script/mech-dump »