| 1 | package WWW::Mechanize::Link; | ||||||||||
| 2 | |||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | WWW::Mechanize::Link - Link object for WWW::Mechanize | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | Link object to encapsulate all the stuff that Mech needs but nobody | ||||||||||
| 13 | wants 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 | |||||||||||
| 28 | For compatibility, this older interface is also supported: | ||||||||||
| 29 | |||||||||||
| 30 | new( $url, $text, $name, $tag, $base, $attr_href ) | ||||||||||
| 31 | |||||||||||
| 32 | Creates and returns a new C<WWW::Mechanize::Link> object. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | sub new { | ||||||||||
| 37 | 65 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | |||||||||||
| 39 | 65 | my $self; | |||||||||
| 40 | |||||||||||
| 41 | # The order of the first four must stay as they are for | ||||||||||
| 42 | # compatibility with older code. | ||||||||||
| 43 | 65 | ▶ | if ( ref $_[0] eq 'HASH' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 63 | $self = [ @{$_[0]}{ qw( url text name tag base attrs ) } ]; | |||||||||
| 45 | } | ||||||||||
| 46 | else { | ||||||||||
| 47 | 2 | $self = [ @_ ]; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 65 | return bless $self, $class; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | =head1 Accessors | ||||||||||
| 54 | |||||||||||
| 55 | =head2 $link->url() | ||||||||||
| 56 | |||||||||||
| 57 | URL from the link | ||||||||||
| 58 | |||||||||||
| 59 | =head2 $link->text() | ||||||||||
| 60 | |||||||||||
| 61 | Text of the link | ||||||||||
| 62 | |||||||||||
| 63 | =head2 $link->name() | ||||||||||
| 64 | |||||||||||
| 65 | NAME attribute from the source tag, if any. | ||||||||||
| 66 | |||||||||||
| 67 | =head2 $link->tag() | ||||||||||
| 68 | |||||||||||
| 69 | Tag name (one of: "a", "area", "frame", "iframe" or "meta"). | ||||||||||
| 70 | |||||||||||
| 71 | =head2 $link->base() | ||||||||||
| 72 | |||||||||||
| 73 | Base URL to which the links are relative. | ||||||||||
| 74 | |||||||||||
| 75 | =head2 $link->attrs() | ||||||||||
| 76 | |||||||||||
| 77 | Returns hash ref of all the attributes and attribute values in the tag. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 217 | ▶ | sub url { return ($_[0])->[0]; } | ||||||||
|
Subroutine
url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 256 | ▶ | sub text { return ($_[0])->[1]; } | ||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 83 | 32 | ▶ | sub name { return ($_[0])->[2]; } | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 84 | 42 | ▶ | sub tag { return ($_[0])->[3]; } | ||||||||
|
Subroutine
tag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | 54 | ▶ | sub base { return ($_[0])->[4]; } | ||||||||
|
Subroutine
base: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 86 | 18 | ▶ | sub attrs { return ($_[0])->[5]; } | ||||||||
|
Subroutine
attrs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 87 | |||||||||||
| 88 | =head2 $link->URI() | ||||||||||
| 89 | |||||||||||
| 90 | Returns the URL as a L<URI::URL> object. | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | sub URI { | ||||||||||
| 95 | 52 | ▶ | my $self = shift; | ||||||||
|
Subroutine
URI: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 96 | |||||||||||
| 97 | 52 | require URI::URL; | |||||||||
| 98 | 52 | my $URI = URI::URL->new( $self->url, $self->base ); | |||||||||
| 99 | |||||||||||
| 100 | 52 | return $URI; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | =head2 $link->url_abs() | ||||||||||
| 104 | |||||||||||
| 105 | Returns a L<URI::URL> object for the absolute form of the string. | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||
| 108 | |||||||||||
| 109 | sub url_abs { | ||||||||||
| 110 | 50 | ▶ | my $self = shift; | ||||||||
|
Subroutine
url_abs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 111 | |||||||||||
| 112 | 50 | return $self->URI->abs; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | =head1 SEE ALSO | ||||||||||
| 116 | |||||||||||
| 117 | L<WWW::Mechanize> and L<WWW::Mechanize::Image> | ||||||||||
| 118 | |||||||||||
| 119 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 120 | |||||||||||
| 121 | Copyright 2004-2010 Andy Lester. | ||||||||||
| 122 | |||||||||||
| 123 | This program is free software; you can redistribute it and/or modify | ||||||||||
| 124 | it under the terms of either: | ||||||||||
| 125 | |||||||||||
| 126 | =over 4 | ||||||||||
| 127 | |||||||||||
| 128 | =item * the GNU General Public License as published by the Free | ||||||||||
| 129 | Software Foundation; either version 1, or (at your option) any later | ||||||||||
| 130 | version, or | ||||||||||
| 131 | |||||||||||
| 132 | =item * the Artistic License version 2.0. | ||||||||||
| 133 | |||||||||||
| 134 | =back | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||
| 137 | |||||||||||
| 138 | # vi:et:sw=4 ts=4 | ||||||||||
| 139 | |||||||||||
| 140 | 10 | 1; | |||||||||