NAME

WWW::Comix::Plugin - base class for plugins in WWW::Comix

SYNOPSIS

use WWW::Comix;

# The constructor for WWW::Comix returns a plugin instance actually
my $comix = WWW::Comix->new(
   comic => 'whatever',
   probe => 'ok',
   directory => '/path/to/repository',
);

# Get current strip and save as 'current.jpg'
$comix->getstore(filename => 'current.jpg');

# Iterate over available strips, getting image data
my $iterator = $comix->get_iterator();
while (my $id = $iterator->()) {
   my $blob = $comix->get(id => $id);
}

DESCRIPTION

This is the real workhorse for WWW::Comix, encapsulating all the logic and leaving the derived classes to implement only three mandatory methods.

This module, and the plugins shipped with it, is proudly based on Moose.

INTERFACE

You will not need to call a constructor directly, use WWW::Comix to get a new object. If you already know the name of the plugin you want to use, just pass it to the "new" in WWW::Comix method:

my $comix = WWW::Comix->new(plugin => $plugin, ...);

The available methods are divided by functionality. Anyway, the methods that you're likely to need are the following:

All the other methods aren't likely to satisfy any need of yours.

Accessors

get_agent

this method can be called either as a class or as an object method. In the former case, it will give back the return value from "get_an_agent", in the latter it will give back the return value from "get_its_agent".

get_an_agent

get a WWW::Mechanize user agent. This method is used to initialise the agent member (see below).

has_agent
set_agent
get_its_agent

each plugin has an agent that will be used for actual WWW interactions. It must support the same interface as WWW::Mechanize (so it will either be a WWW::Mechanize object, or an object of some derived class).

By default gets an agent invoking "get_an_agent". You can tell if an agent has already been set via the has_agent method; the other two methods are the normal setter/getter.

has_directory
set_directory
get_directory

the "getstore" method (see below) will save files inside a directory.

You can tell if a directory has been set with the has_directory predicate method. When needed, by default it will be set to ..

set_status
is_ok

this holds the (boolean) status of the plugin. Each plugin can have its idea of what a "wrong" status is.

set_comic
get_comic

the comic that this plugin will deal with. You are obliged to pass at least a comic name during the construction, but you can change your mind later. Note that if you change the comic name to some unsupported comic Bad Things can happen.

get_name

get plugin's name.

get_priority

get plugin's priority.

The priority is (or can be) used to establish the best provider for any given comic. The lower the value, the higher the priority.

get_comics_list

get the list of comics provided by the plugin.

Returns the list of available comics; it has no parameter.

get_available_ids

get the list of available ids for the configured comic (see "set_comic" and "get_comic").

Returns the list of available valid ids for the given plugin/comic; it has no parameter.

Note that this method is always overriden by the specific plugin.

get_id_iterator

get an iterator to cycle on all the available ids for the comic.

The iterator is a sub that can be called without parameters to get the next item in the list. Returns undef once the list is exhausted.

It has no parameters.

get_current_id

get the id of the latest available strip. This is the same as the first item in the list returned by "get_available_ids", or the item returned by the first invocation of an iterator taken with "get_id_iterator".

Returns a valid identifier for the given plugin/comic. It has no parameters.

get_filename

get the full path to the file where "getstore" will save the downloaded data.

Returns the filename. Accepts the following named parameters:

filename

the filename to use. If not provided, "guess_filename" will be called to make a reasonable guess.

If this parameter is a reference to a sub, it will be invoked with a reference to the object and all the available parameters passed to the "get_filename" method itself.

directory

the directory where the file should be saved into. Defaults to what "get_directory" says.

guess_filename

try to figure out a sensible filename for a downloaded strip.

Returns an absolute path to a file. Requires a mandatory named parameter response, which should hold a reference to a HTTP::Response object.

normalise_filename

try to normalise a file name, e.g. giving it a sensible extension and ensuring that it will not become a hidden file in some systems.

Accepts the following named parameters:

filename (mandatory)

the filename to normalise;

response (mandatory)

a HTTP::Response object associated with the image whose filename you would like to normalise.

guess_file_extension

guess filename extension for image file based on the content type or the image's first data octets.

Returns the guessed file extension, or dies trying. Requires a mandatory named parameter response, which holds a reference to a HTTP::Response object.

id_to_uri

turn a comic id into a URI pointing towards the image file.

Accepts the id as the only parameter (non-named). Returns a URI.

Note that this method has to be overridden in a derived plugin.

probe

probe the remote site for available comics.

Note that this method has to be overridden in a derived plugin.

get_config
set_config

these are actually class methods and not instance methods, and are useful to set plugin-specific configurations for each comic.

It has to be set to a hash where keys are feature names, and the values can be anything a plugin deems necessary. The hash is used by "get_comics_list" to return the names of the available features.

get_config returns the hash; depending on the call context (scalar or list), it does the right thing. Accepts the optional named parameter probe, to trigger a "probe" towards the remote site.

set_config accepts either a single reference to a hash, or a list that will be turned into a hash. Returns nothing.

BUILD

Not to be used directly.

get

get the comic or die trying.

Returns a HTTP::Response object if successful, croaks otherwise.

Accepts a named parameter id that is the identifier for the strip to download; defaults to the id given back by "get_current_id".

getstore

get the comic and saves to file, or die trying.

Accepts the following named parameters:

id

the identifier for the strip to download; defaults to the id given back by "get_current_id".

filename
directory

passed on to "get_filename" to determine the final filename.

Accepts a name

get_http_response

get the comic and return what the User Agent gives it back, whatever it is (i.e. either a HTTP::Response object, or undef).

Accepts a named parameter id that is the identifier for the strip to download; defaults to the id given back by "get_current_id".

Adding A Plugin

Integrating a new plugin requires that you derive your new module from WWW::Comix::Plugin, and that you override at least the following methods:

Probing is where you set the available comics, together with any information you think necessary. The "probe" method must be regarded as a class method, and is supposed to set the configuration hash via "set_config". For example, if you already know that your plugin is going to provide only the two strips Foo bars and Baz the Great, you could do the following:

sub probe {
   my $sp = shift; # sp stands for "self or package"
   $sp->set_config(
      'Foo bars' => 'http://foo-bars.example.com/archive/',
      'Baz the Great' => 'http://baz-the-great.example.com/btg/',
   );
   return;
}

How you're going to use the values is up to you, you can set whatever you want.

As a general note, if you foresee that the "get_available_ids" can be too resource demanding (e.g. because the whole list is spread over many pages), you should turn to an iterator-based implementation like this:

sub get_available_ids {
   my $self = shift;
   my @retval;
   my $it = $self->get_id_iterator();
   while (my $id = $it->()) {
      push @retval, $id;
   }
   return @retval;
}

sub get_id_iterator {
   # Override the parent's method here, with a more complicated
   # but less resource-demanding logic.
}

You can see examples of this in WWW::Comix::Plugin::Creators and WWW::Comix::Plugin::GoComics.

DIAGNOSTICS

Some errors can be generated by the Moose system; notably, if you call the new method without providing the comic parameters, that is mandatory.

derived classes MUST implement %s

you're trying to use some plugin that didn't implement all the needed methods, see "Adding A Plugin".

plugin %s: didn't probe, no configuration

Before asking for available comics, or even get the configurations specific to some plugin, you have to call "probe". You can pass the probe parameter to the call, anyway.

couldn't get probe page '%s': %s

something wrong with the Internet connection, apparently.

unhandled comic '%s'

the given comic is not supported by this plugin.

open('%s'): %s

this error can be given back by "getstore" when trying to open a file for writing the retrieved image data. The error given back by the Operating System is reported in the error message.

can't guess a filename without a HTTP::Response

"guess_filename" needs at least a response parameter holding a reference to an HTTP::Response object to work properly.

can't normalise a filename without a filename

don't try to call "normalise_filename" without providing a filename parameter. Ok, it's actually refusing to call your file 0 actually.

can't guess file extension without a HTTP::Response

nothing more to say, be sure to include a response parameter holding a reference to a HTTP::Response object when calling "guess_file_extension" and "normalise_filename".

can't guess type of file, bailing out

"guess_file_extension" (which is called by "normalise_filename") couldn't determine a suitable file extension for the given image. And it tries hard.

error getting '%s': $s

either "get" or "getstore" had problems downloading the given image.

AUTHOR

Flavio Poletti <flavio [at] polettix [dot] it>

LICENCE AND COPYRIGHT

Copyright (c) 2008, Flavio Poletti <flavio [at] polettix [dot] it>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl 5.8.x itself. See perlartistic and perlgpl.

Questo modulo è software libero: potete ridistribuirlo e/o modificarlo negli stessi termini di Perl 5.8.x stesso. Vedete anche perlartistic e perlgpl.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

NEGAZIONE DELLA GARANZIA

Poiché questo software viene dato con una licenza gratuita, non c'è alcuna garanzia associata ad esso, ai fini e per quanto permesso dalle leggi applicabili. A meno di quanto possa essere specificato altrove, il proprietario e detentore del copyright fornisce questo software "così com'è" senza garanzia di alcun tipo, sia essa espressa o implicita, includendo fra l'altro (senza però limitarsi a questo) eventuali garanzie implicite di commerciabilità e adeguatezza per uno scopo particolare. L'intero rischio riguardo alla qualità ed alle prestazioni di questo software rimane a voi. Se il software dovesse dimostrarsi difettoso, vi assumete tutte le responsabilità ed i costi per tutti i necessari servizi, riparazioni o correzioni.

In nessun caso, a meno che ciò non sia richiesto dalle leggi vigenti o sia regolato da un accordo scritto, alcuno dei detentori del diritto di copyright, o qualunque altra parte che possa modificare, o redistribuire questo software così come consentito dalla licenza di cui sopra, potrà essere considerato responsabile nei vostri confronti per danni, ivi inclusi danni generali, speciali, incidentali o conseguenziali, derivanti dall'utilizzo o dall'incapacità di utilizzo di questo software. Ciò include, a puro titolo di esempio e senza limitarsi ad essi, la perdita di dati, l'alterazione involontaria o indesiderata di dati, le perdite sostenute da voi o da terze parti o un fallimento del software ad operare con un qualsivoglia altro software. Tale negazione di garanzia rimane in essere anche se i dententori del copyright, o qualsiasi altra parte, è stata avvisata della possibilità di tali danneggiamenti.

Se decidete di utilizzare questo software, lo fate a vostro rischio e pericolo. Se pensate che i termini di questa negazione di garanzia non si confacciano alle vostre esigenze, o al vostro modo di considerare un software, o ancora al modo in cui avete sempre trattato software di terze parti, non usatelo. Se lo usate, accettate espressamente questa negazione di garanzia e la piena responsabilità per qualsiasi tipo di danno, di qualsiasi natura, possa derivarne.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 722:

Non-ASCII character seen before =encoding in 'è'. Assuming CP1252