File Coverage

blib/lib/WWW/Mechanize/Image.pm
Criterion Covered Total %
statement 28 28 100.0
branch 3 4 75.0
condition 1 2 50.0
subroutine 13 13 100.0
pod 11 11 100.0
total 56 58 96.5


line stmt bran cond sub pod time code
1             package WWW::Mechanize::Image;
2              
3 4     4   54902 use strict;
  4         14  
  4         114  
4 4     4   57 use warnings;
  4         7  
  4         1537  
5              
6             our $VERSION = '2.15';
7              
8             #ABSTRACT: Image object for WWW::Mechanize
9              
10              
11             sub new {
12 40     40 1 184 my $class = shift;
13 40   50     90 my $params = shift || {};
14              
15 40         70 my $self = bless {}, $class;
16              
17 40         72 for my $param ( qw( url base tag height width alt name attrs ) ) {
18             # Check for what we passed in, not whether it's defined
19 320 100       664 $self->{$param} = $params->{$param} if exists $params->{$param};
20             }
21              
22             # url and tag are always required
23 40         55 for ( qw( url tag ) ) {
24 80 50       143 exists $self->{$_} or die "WWW::Mechanize::Image->new must have a $_ argument";
25             }
26              
27 40         146 return $self;
28             }
29              
30              
31 407     407 1 59595 sub url { return ($_[0])->{url}; }
32 126     126 1 297 sub base { return ($_[0])->{base}; }
33 1     1 1 3 sub name { return ($_[0])->{name}; }
34 189     189 1 1285 sub tag { return ($_[0])->{tag}; }
35 7     7 1 134 sub height { return ($_[0])->{height}; }
36 2     2 1 7 sub width { return ($_[0])->{width}; }
37 76     76 1 601 sub alt { return ($_[0])->{alt}; }
38 299     299 1 2736 sub attrs { return ($_[0])->{attrs}; }
39              
40              
41             sub URI {
42 125     125 1 1207 my $self = shift;
43              
44 125         1173 require URI::URL;
45 125         9828 my $URI = URI::URL->new( $self->url, $self->base );
46              
47 125         21697 return $URI;
48             }
49              
50              
51             sub url_abs {
52 123     123 1 14184 my $self = shift;
53              
54 123         194 return $self->URI->abs;
55             }
56              
57              
58             1;
59              
60             __END__