WWW::Mechanize::Meta - Adds HEAD tag parsing to WWW::Mechanize


WWW-Mechanize-Meta documentation Contained in the WWW-Mechanize-Meta distribution.

Index


Code Index:

NAME

Top

WWW::Mechanize::Meta - Adds HEAD tag parsing to WWW::Mechanize

VERSION

Top

Version 0.07

SYNOPSIS

Top

    use WWW::Mechanize::Meta;

    my $mech = WWW::Mechanize::Meta->new();
    my @css=$mech->link('stylesheet');
    foreach (@css){
	print "$_->{href}\n";
    }




METHODS

Top

rss

Returns all rss objects for this page

headtag

Returns raw header object

INTERNAL METHODS

Top

new

title

update_html

_parse_head

AUTHOR

Top

Andrey Kostenko, <andrey@kostenko.name>

BUGS

Top

Please report any bugs or feature requests to bug-www-mechanize-meta at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Mechanize-Meta. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc WWW::Mechanize::Meta

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/WWW-Mechanize-Meta

* CPAN Ratings

http://cpanratings.perl.org/d/WWW-Mechanize-Meta

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Meta

* Search CPAN

http://search.cpan.org/dist/WWW-Mechanize-Meta

ACKNOWLEDGEMENTS

Top

LICENSE

Top

Copyright 2007 Andrey Kostenko, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


WWW-Mechanize-Meta documentation Contained in the WWW-Mechanize-Meta distribution.
package WWW::Mechanize::Meta;

use warnings;
use strict;
use Data::Dumper;
use HTTP::Headers;
use HTML::HeadParser;

use base 'WWW::Mechanize';

our $VERSION = '0.07';

sub link {
    my $self = shift;
    my $type = shift;
    my @links;
    foreach my $link ( $self->{head}->header('link') ) {

        my @params = split '; ', $link;
        my ($src) = ( ( shift @params ) =~ m/\<(.*)\>/ );
        my %params = map { m/(.*)=\"([^\"]*)\"/ } @params;
        $params{href} = $src;
        push @links, \%params if !$type || $params{rel} eq $type;
    }
    return @links;

}

sub rss {
    my $self  = shift;
    my @links = $self->link('alternate');
    my @news;
    foreach (@links) {
        push @news, $_
          if $_->{type} eq 'application/rss+xml'
              or $_->{type} eq 'application/atom+xml';
    }
    return @news;

}

sub headtag {
    my $self = shift;
    return $self->{head};
}

sub new {
    my $class = shift;
    my $self  = $class->SUPER::new(@_);
    $self->{headparser} = HTML::HeadParser->new();
    return $self;
}

sub title {
    my $self = shift;
    return unless $self->is_html;
    my $title = $self->{head}->header('Title');
    return $title;
}

sub update_html {
    my $self = shift;
    my $html = shift;
    $self->SUPER::update_html($html);

    #    warn $html;
    if ( $self->is_html ) {
        utf8::decode($html);
        $self->{headparser}{'header'} = HTTP::Headers->new();
        $self->{headparser}->parse($html);
        $self->{head} = $self->{headparser}->header;
    }
    else {
        $self->{head} = undef;
        $self->{link} = undef;
    }
    return;
}

sub _parse_head {
    my $self = shift;
    return unless $self->is_html;
    require HTML::HeadParser;
    my $p = HTML::HeadParser->new;
    $p->parse( $self->content );
}

1;    # End of WWW::Mechanize::Meta