Randy Stauner > Plack-Middleware-Mirror-0.401 > Plack::Middleware::Mirror

Download:
Plack-Middleware-Mirror-0.401.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.401   Source  

NAME ^

Plack::Middleware::Mirror - Save responses to disk to mirror a site

VERSION ^

version 0.401

SYNOPSIS ^

  # app.psgi
  use Plack::Builder;

  builder {
    # other middleware...

    # save response to disk (beneath $dir) if uri matches
    enable Mirror => path => $match, mirror_dir => $dir;

    # your app...
  };


  # A specific example: Build your own mirror

  # app.psgi
  use Plack::Builder;

  builder {
    # serve the request from the disk if it exists
    enable Static =>
      path => $config->{match_uri},
      root => $config->{mirror_dir},
      pass_through => 1;
    # if it doesn't exist yet, request it and save it
    enable Mirror =>
      path => $config->{match_uri},
      mirror_dir => $config->{mirror_dir};
    Plack::App::Proxy->new( remote => $config->{remote_uri} )->to_app
  };

DESCRIPTION ^

  NOTE: This module is in an alpha stage.
  Only the simplest case of static file request has been considered.
  Handling of anything with a QUERY_STRING is currently undefined.
  Suggestions, patches, and pull requests are welcome.

This middleware will save the content of the response in a tree structure reflecting the URI path info to create a mirror of the site on disk.

This is different than Plack::Middleware::Cache which saves the entire response (headers and all) to speed response time on subsequent and lessen external network usage.

In contrast this middleware saves the static file requested to the disk preserving the file name and directory structure. This creates a physical mirror of the site so that you can do other things with the directory structure if you desire.

This is probably most useful when combined with Plack::Middleware::Static and Plack::App::Proxy to build up a mirror of another site transparently, downloading only the files you actually request instead of having to spider the whole site.

However if you have a reason to copy the responses from your own web app onto disk you're certainly free to do so (a interesting form of backup perhaps).

NOTE: This middleware does not short-circuit the request (as Plack::Middleware::Cache does), so if there is no other middleware to stop the request this module will let the request continue and save the latest version of the response each time. This is considered a feature.

OPTIONS ^

path

This specifies the condition used to match the request (PATH_INFO). It can be either a regular expression or a callback (code ref) that can match against $_ or even modify it to alter the path of the file that will be saved to disk.

It works just like the path argument to Plack::Middleware::Static since the code was stolen right from there.

mirror_dir

This is the directory beneath which files will be saved.

status_codes

This to an array ref of acceptable status codes to mirror. The default is [ 200 ] which means that only a normal 200 OK response will be saved.

Set this to an empty array ref ([]) to mirror regardless of response code.

debug

Set this to true to print debugging statements to STDERR.

TODO ^

SEE ALSO ^

SUPPORT ^

Perldoc

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

  perldoc Plack::Middleware::Mirror

Websites

The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-plack-middleware-mirror at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plack-Middleware-Mirror. You will be automatically notified of any progress on the request by the system.

Source Code

http://github.com/rwstauner/Plack-Middleware-Mirror

  git clone http://github.com/rwstauner/Plack-Middleware-Mirror

AUTHOR ^

Randy Stauner <rwstauner@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2011 by Randy Stauner.

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

syntax highlighting: