Emmanuel Rodriguez > WWW-Mechanize-Plugin-AutoWrite-0.06 > WWW::Mechanize::Plugin::AutoWrite

Download:
WWW-Mechanize-Plugin-AutoWrite-0.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.06   Source  

NAME ^

WWW::Mechanize::Plugin::AutoWrite - WWW::Mechanize plugin that writes the fetched pages to the disk.

SYNOPSIS ^

        use WWW::Mechanize;
        use WWW::Mechanize::Plugin::AutoWrite;
        
        my $mech = WWW::Mechanize->new();
        $mech->autowrite->file('/tmp/mech.html');
        
        $mech->get('http://search.cpan.org/');
        # now the contents of the page is written to /tmp/mech.html

or:

        my $mech = WWW::Mechanize->new();
        $mech->autowrite->dir('/tmp/mech/');
        
        $mech->get('http://search.cpan.org/');
        # now the contents of the page are written to /tmp/mech/001.html and the HTTP
        # transaction is logged into /tmp/mech/001.http

        $mech->submit_form(
                'form_name' => 'f',
                'fields'    => {
                        'query' => 'WWW::Mechanize::Plugin::AutoWrite',
                        'mode'  => 'module', 
                },
        );
        # Now the pages are saved into /tmp/mech/002.html and /tmp/mech/002.http

or:

        my $mech = WWW::Mechanize->new();
        $mech->autowrite->dir('/tmp/mech/');           # Save the whole session
        $mech->autowrite->file('/tmp/mech/last.html'); # Save the last page in a file
        
        $mech->get('http://www.wikipedia.com/');
        # now the contents of the page are written both to /tmp/mech/001.html and 
        # /tmp/mech/last.html
        $mech->follow_link(text => 'Galego');

DESCRIPTION ^

WWW::Mechanize::Plugin::AutoWrite overrides the method WWW::Mechanize::request with a custom version that records all HTTP transactions into the disk. This has for effect that every time that a new HTTP request is made (GET, POST, etc) the contents of the page returned by the server and the HTTP transaction (the request and the response) are stored into local file(s) on disk.

If no destination file/folder is provided then this module will act as a noop and nothing will be written to the disk. It's also possible to provide both a file and a folder in order to have the HTTP session and the last page saved simultaneously.

RATIONALE ^

The idea is to have the static page loaded into a web browser and to reload the page as needed. A better idea is to use a browser that has a builtin mechanism for monitoring changes to local files. The epiphany web browser does this automatically once a page is loaded through the procotol file://

Another reason for the existence of this module is to be able to trace an HTTP transaction in order to debug better mechanizing operations performed on complex web sites.

ATTRIBUTES ^

This module can be configured through the attributes enumerated here.

file

Get/set the name of the file where the last page downloaded (the content's of the HTTP response) will be saved.

Set this attribute to a false value in order to disable the saving of the last page downloaded.

dir

Get/set the name of the folder where the HTTP session (the content's of the HTTP response as well as the HTTP headers) will be saved.

Set this attribute to a false value in order to disable the saving of the HTTP session.

counter

Get/set the counter used no name each file with a unique name when saving the HTTP session (the counter is used only when "dir" is set).

It can be useful to reset the counter when multiple sessions need to be saved into different folders.

        foreach my $entry (@entries) {
                $mech->autowrite->dir("/tmp/$entry/");
                $mech->autowrite->counter(0);
                # Complex mechanize             
                mechanize_process($mech, $entry);
        }

METHODS ^

This module offers the following public methods:

write_to_file

This method writes the HTTP requests into a file and/or a folder. It's called automatically by mechanize once the plugin is loaded and configured.

WWW::Mechanize::request ^

The method "request" in WWW::Mechanize is overriden by a custom version that will invoke the original "request" in WWW::Mechanize and then record the request.

WWW::Mechanize::autowrite ^

This accessor returns the autowrite instance associated with this mechanize instance. The first time that this method is invoked it will create

COMPATIBILITY ^

The version 0.04 has a different API and is not backward compatible. This affects only the configuration of the plugin. The behaviour should be the same.

SEE ALSO ^

http://search.cpan.org/perldoc?WWW::Mechanize::Plugin::Display

AUTHOR ^

Jozef Kutej, <jkutej@cpan.org>,

Emmanuel Rodriguez, <potyl@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2007 by Jozef Kutej Copyright (C) 2008 by Jozef Kutej, Emmanuel Rodriguez

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: