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


        use WWW::Mechanize;
        use WWW::Mechanize::Plugin::AutoWrite;
        my $mech = WWW::Mechanize->new();
        # now the contents of the page is written to /tmp/mech.html


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

                '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


        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
        # now the contents of the page are written both to /tmp/mech/001.html and 
        # /tmp/mech/last.html
        $mech->follow_link(text => 'Galego');


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.


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.


This module can be configured through the attributes enumerated here.


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.


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.


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) {
                # Complex mechanize             
                mechanize_process($mech, $entry);


This module offers the following public methods:


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.


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.


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


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.



Jozef Kutej, <>,

Emmanuel Rodriguez, <>


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.