Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / WWW / Mechanize / Image.pm
1 package WWW::Mechanize::Image;
2 # vi:et:sw=4 ts=4
3
4 use strict;
5 use warnings;
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     my $class = shift;
35     my $parms = shift || {};
36
37     my $self = bless {}, $class;
38
39     for my $parm ( qw( url base tag height width alt name ) ) {
40         # Check for what we passed in, not whether it's defined
41         $self->{$parm} = $parms->{$parm} if exists $parms->{$parm};
42     }
43
44     # url and tag are always required
45     for ( qw( url tag ) ) {
46         exists $self->{$_} or die "WWW::Mechanize::Image->new must have a $_ argument";
47     }
48
49     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 sub url     { return ($_[0])->{url}; }
85 sub base    { return ($_[0])->{base}; }
86 sub name    { return ($_[0])->{name}; }
87 sub tag     { return ($_[0])->{tag}; }
88 sub height  { return ($_[0])->{height}; }
89 sub width   { return ($_[0])->{width}; }
90 sub alt     { return ($_[0])->{alt}; }
91
92 =head2 $link->URI()
93
94 Returns the URL as a L<URI::URL> object.
95
96 =cut
97
98 sub URI {
99     my $self = shift;
100
101     require URI::URL;
102     my $URI = URI::URL->new( $self->url, $self->base );
103
104     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     my $self = shift;
115
116     return $self->URI->abs;
117 }
118
119 =head1 COPYRIGHT
120
121 Copyright (c) 2004 Andy Lester. All rights reserved. This program is
122 free software; you can redistribute it and/or modify it under the same
123 terms as Perl itself.
124
125 =cut
126
127 1;