| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Mechanize::Meta; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 190646 | use warnings; | 
|  | 4 |  |  |  |  | 11 |  | 
|  | 4 |  |  |  |  | 148 |  | 
| 4 | 4 |  |  | 4 |  | 21 | use strict; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 160 |  | 
| 5 | 4 |  |  | 4 |  | 15020 | use Data::Dumper; | 
|  | 4 |  |  |  |  | 74576 |  | 
|  | 4 |  |  |  |  | 312 |  | 
| 6 | 4 |  |  | 4 |  | 6251 | use HTTP::Headers; | 
|  | 4 |  |  |  |  | 47122 |  | 
|  | 4 |  |  |  |  | 181 |  | 
| 7 | 4 |  |  | 4 |  | 5455 | use HTML::HeadParser; | 
|  | 4 |  |  |  |  | 50634 |  | 
|  | 4 |  |  |  |  | 182 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 4 |  |  | 4 |  | 49 | use base 'WWW::Mechanize'; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 7027 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 NAME | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | WWW::Mechanize::Meta - Adds HEAD tag parsing to WWW::Mechanize | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 VERSION | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | Version 0.07 | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =cut | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | our $VERSION = '0.07'; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | use WWW::Mechanize::Meta; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | my $mech = WWW::Mechanize::Meta->new(); | 
| 28 |  |  |  |  |  |  | my @css=$mech->link('stylesheet'); | 
| 29 |  |  |  |  |  |  | foreach (@css){ | 
| 30 |  |  |  |  |  |  | print "$_->{href}\n"; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 METHODS | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =head2 link( [$type] ) | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | Returns link tag with attribure rel = $type. If no attribute $type given, returns all link tags. | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =cut | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub link { | 
| 43 | 3 |  |  | 3 | 1 | 20 | my $self = shift; | 
| 44 | 3 |  |  |  |  | 5 | my $type = shift; | 
| 45 | 3 |  |  |  |  | 7 | my @links; | 
| 46 | 3 |  |  |  |  | 16 | foreach my $link ( $self->{head}->header('link') ) { | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 16 |  |  |  |  | 192 | my @params = split '; ', $link; | 
| 49 | 16 |  |  |  |  | 95 | my ($src) = ( ( shift @params ) =~ m/\<(.*)\>/ ); | 
| 50 | 16 |  |  |  |  | 34 | my %params = map { m/(.*)=\"([^\"]*)\"/ } @params; | 
|  | 39 |  |  |  |  | 419 |  | 
| 51 | 16 |  |  |  |  | 35 | $params{href} = $src; | 
| 52 | 16 | 100 | 66 |  |  | 248 | push @links, \%params if !$type || $params{rel} eq $type; | 
| 53 |  |  |  |  |  |  | } | 
| 54 | 3 |  |  |  |  | 12 | return @links; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head2 rss | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | Returns all rss objects for this page | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =cut | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub rss { | 
| 65 | 2 |  |  | 2 | 1 | 32 | my $self  = shift; | 
| 66 | 2 |  |  |  |  | 10 | my @links = $self->link('alternate'); | 
| 67 | 2 |  |  |  |  | 6 | my @news; | 
| 68 | 2 |  |  |  |  | 5 | foreach (@links) { | 
| 69 | 4 | 100 | 100 |  |  | 34 | push @news, $_ | 
| 70 |  |  |  |  |  |  | if $_->{type} eq 'application/rss+xml' | 
| 71 |  |  |  |  |  |  | or $_->{type} eq 'application/atom+xml'; | 
| 72 |  |  |  |  |  |  | } | 
| 73 | 2 |  |  |  |  | 15 | return @news; | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head2 headtag | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | Returns raw header object | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =cut | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub headtag { | 
| 84 | 1 |  |  | 1 | 1 | 249 | my $self = shift; | 
| 85 | 1 |  |  |  |  | 13 | return $self->{head}; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head1 INTERNAL METHODS | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =head2 new | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =cut | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub new { | 
| 95 | 3 |  |  | 3 | 1 | 50 | my $class = shift; | 
| 96 | 3 |  |  |  |  | 48 | my $self  = $class->SUPER::new(@_); | 
| 97 | 3 |  |  |  |  | 127970 | $self->{headparser} = HTML::HeadParser->new(); | 
| 98 | 3 |  |  |  |  | 1556 | return $self; | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head2 title | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =cut | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | sub title { | 
| 106 | 1 |  |  | 1 | 1 | 18 | my $self = shift; | 
| 107 | 1 | 50 |  |  |  | 5 | return unless $self->is_html; | 
| 108 | 1 |  |  |  |  | 19 | my $title = $self->{head}->header('Title'); | 
| 109 | 1 |  |  |  |  | 43 | return $title; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =head2 update_html | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =cut | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub update_html { | 
| 117 | 6 |  |  | 6 | 1 | 4169328 | my $self = shift; | 
| 118 | 6 |  |  |  |  | 27 | my $html = shift; | 
| 119 | 6 |  |  |  |  | 55 | $self->SUPER::update_html($html); | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | #    warn $html; | 
| 122 | 6 | 50 |  |  |  | 157 | if ( $self->is_html ) { | 
| 123 | 6 |  |  |  |  | 477 | utf8::decode($html); | 
| 124 | 6 |  |  |  |  | 71 | $self->{headparser}{'header'} = HTTP::Headers->new(); | 
| 125 | 6 |  |  |  |  | 258 | $self->{headparser}->parse($html); | 
| 126 | 6 |  |  |  |  | 13177 | $self->{head} = $self->{headparser}->header; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  | else { | 
| 129 | 0 |  |  |  |  | 0 | $self->{head} = undef; | 
| 130 | 0 |  |  |  |  | 0 | $self->{link} = undef; | 
| 131 |  |  |  |  |  |  | } | 
| 132 | 6 |  |  |  |  | 88 | return; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =head2 _parse_head | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =cut | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | sub _parse_head { | 
| 140 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 141 | 0 | 0 |  |  |  |  | return unless $self->is_html; | 
| 142 | 0 |  |  |  |  |  | require HTML::HeadParser; | 
| 143 | 0 |  |  |  |  |  | my $p = HTML::HeadParser->new; | 
| 144 | 0 |  |  |  |  |  | $p->parse( $self->content ); | 
| 145 |  |  |  |  |  |  | } | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =head1 AUTHOR | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | Andrey Kostenko, C<<  >> | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head1 BUGS | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 154 |  |  |  |  |  |  | C, or through the web interface at | 
| 155 |  |  |  |  |  |  | L. | 
| 156 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 157 |  |  |  |  |  |  | your bug as I make changes. | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =head1 SUPPORT | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | perldoc WWW::Mechanize::Meta | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | You can also look for information at: | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =over 4 | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | L | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | L | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | L | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =item * Search CPAN | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | L | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | =back | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head1 LICENSE | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | Copyright 2007 Andrey Kostenko, all rights reserved. | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 194 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | =cut | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | 1;    # End of WWW::Mechanize::Meta |