Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / WWW / Mechanize / Link.pm
CommitLineData
3fea05b9 1package WWW::Mechanize::Link;
2
3use strict;
4use warnings;
5
6=head1 NAME
7
8WWW::Mechanize::Link - Link object for WWW::Mechanize
9
10=head1 SYNOPSIS
11
12Link object to encapsulate all the stuff that Mech needs but nobody
13wants to deal with as an array.
14
15=head1 Constructor
16
17=head2 new()
18
19 my $link = WWW::Mechanize::Link->new( {
20 url => $url,
21 text => $text,
22 name => $name,
23 tag => $tag,
24 base => $base,
25 attr => $attr_href,
26 } );
27
28For compatibility, this older interface is also supported:
29
30 new( $url, $text, $name, $tag, $base, $attr_href )
31
32Creates and returns a new C<WWW::Mechanize::Link> object.
33
34=cut
35
36sub new {
37 my $class = shift;
38
39 my $self;
40
41 # The order of the first four must stay as they are for
42 # compatibility with older code.
43 if ( ref $_[0] eq 'HASH' ) {
44 $self = [ @{$_[0]}{ qw( url text name tag base attrs ) } ];
45 }
46 else {
47 $self = [ @_ ];
48 }
49
50 return bless $self, $class;
51}
52
53=head1 Accessors
54
55=head2 $link->url()
56
57URL from the link
58
59=head2 $link->text()
60
61Text of the link
62
63=head2 $link->name()
64
65NAME attribute from the source tag, if any.
66
67=head2 $link->tag()
68
69Tag name (one of: "a", "area", "frame", "iframe" or "meta").
70
71=head2 $link->base()
72
73Base URL to which the links are relative.
74
75=head2 $link->attrs()
76
77Returns hash ref of all the attributes and attribute values in the tag.
78
79=cut
80
81sub url { return ($_[0])->[0]; }
82sub text { return ($_[0])->[1]; }
83sub name { return ($_[0])->[2]; }
84sub tag { return ($_[0])->[3]; }
85sub base { return ($_[0])->[4]; }
86sub attrs { return ($_[0])->[5]; }
87
88=head2 $link->URI()
89
90Returns the URL as a L<URI::URL> object.
91
92=cut
93
94sub URI {
95 my $self = shift;
96
97 require URI::URL;
98 my $URI = URI::URL->new( $self->url, $self->base );
99
100 return $URI;
101}
102
103=head2 $link->url_abs()
104
105Returns a L<URI::URL> object for the absolute form of the string.
106
107=cut
108
109sub url_abs {
110 my $self = shift;
111
112 return $self->URI->abs;
113}
114
115=head1 COPYRIGHT
116
117Copyright (c) 2004-2008 Andy Lester. All rights reserved. This program is
118free software; you can redistribute it and/or modify it under the same
119terms as Perl itself.
120
121=cut
122
123# vi:et:sw=4 ts=4
124
1251;