The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Slides::Controller::Single - main base class for controllers based in I/O

VERSION

This document describes WWW::Slides::Controller::Single version 0.0.9

SYNOPSIS

   use WWW::Slides::Controller::Single;

   # See WWW::Slides::Controller::STDIO out anyway...
   my $IO_controller = WWW::Slides::Controller::Single->new(
      in_handle  => \*STDIN,
      out_handle => \*STDOUT,
   );

   # Be sure to check WWW::Slides::Controller::TCP as well,
   # life can be easier
   use IO::Socket;
   my $listener = IO::Socket->new(LocalPort => $port, Listen => 1);
   my $sock = $listener->accept();
   my $TCP_controller = WWW::Slides::Controller::Single->new(
      in_handle  => $sock,
      out_handle => $sock,
   );

  

DESCRIPTION

This module represents the main base class for building up controllers in the WWW::Slides system. It is able to interact with WS::Talk objects in order to pilot all the aspects of a talk (see the documentation for WWW::Slides::Talk for more info on this).

While not normally used directly, this class can still be useful when used on its own. The main interface is through two handles, one used for input commands, one for putting out messages regarding those commands. The two handles can be the same (as in the case of a TCP socket) or different (for example using the standard streams). Subclass normally only add the needed logic to automatically set those handles up, but they can expand functionalities, of course.

The WWW::System is talk-centric, i.e. the main object is (or should be) the WS::Talk one (it's also the only containing a run() method, so you have probably already worked this out). For these reasons, a generic Controller has two main interaction points:

  • in the first place, it provides facility for registering/releasing a selector, i.e. an object that will be (hopefully) used like a IO::Select one (ok, 99.9% of the times it will be an IO::Select object). A WS::Talk uses an IO::Select object to keep track of all possible sources of input data (attendee inputs, controllers, etc.), so registering the selector allows the controller set the right bits in the selector itself.

    While this may seem a bit contrived in our case, because there's only a single input handle to look after, with this mechanism the Controller interface is able to deal with the possibility that a controller handles, behind the scenes, multiple inputs. This is the case of WWW::Slides::Controller::Multiple and its main descendant WWW::Slides::Controller::TCP, so WS::Controller::Single is no exception and adheres to this interface.

  • On the actual controlling side, it provides the execute_commands() method, that grabs input commands and (tries to) execute them on the WS::Talk object. This is where the actual work is done, where the remote API is implemented and so the piece of code that's actually reused without any addition. Any command addition, of course, is likely to extend this command.

INTERFACE

As described in the previous section, the two main parts in this class are the selector management and the command execution ones. But we also have other methods, of course, like the contruction and some general handling methods.

Object Life Management

These methods deal with the general management of object's life, like creation, check and shutdown.

new(...)

Like all constructors in the Object::InsideOut system, you have two different ways to build up an object. All parameters are named ones, so you have to either pass a reference to a hash, or something that resembles a hash by its own. The recognised named parameters are the following:

in_handle (mandatory)

The input handle where the commands come from. This handle should support any method that IO::Handle provides, so you should safely use regular filehandles, standard streams, TCP streams and so on.

out_handle (optional)

The output handle where command responses are sent to. If not set, outputs are simply discarded (it's up to you decide if this is acceptable or not).

selector (optional)

The selector object we were talking about in DESCRIPTION. Unless you know that there is some command available in other ways, you should probably set a value for this parameter (or set it later with set_selector(), see below) otherwise you'll risk to have blocking reads when calling execute_commands() and/or get_commands(). Caveat Emptor.

is_alive()

This method tells if the object is still alive or not, i.e. if it is still able to receive commands or not. For example, if the input channel gets closed, the object's status is set to not alive (see also shut_down() below).

shut_down()

Perform correct cleanup before object termination. This method should probably be called by the destructor, but at the moment it's not so and it is called when the end-of-file condition is seen in input. This method also releases the currently registered selector invoking release_selector().

Selector Management

set_selector($selector)

Set the current selector. The $selector parameter should be a reference to the selector object.

In WS::Controller::Single, this method invokes:

   $selector->add($in_handle);

where $in_handle is the handle where the input commands are taken from.

selector()

Get a reference to the currently set selector.

release_selector()

Release the selector, i.e. unregisters the selector and unregisters from the selector. in WS::Controller::Single this method invokes:

   $self->selector()->remove($in_handle);

where $in_handle is the handle where the input commands are taken from.

Command Execution

The main command execution method is execute_commands(), and clients should normally only need this. The other methods can be used mainly for subclassing. This whole interface is part of the "general concept" of what a Controller should support.

execute_commands($filehandle, $talk)

Get commands from the input and execute them on the $talk object. The $filehandle parameter is actually ignored in WS::Controller::Single, because its main usage is in WWW::Slides::Multiple controllers in order to avoid repeating the selection on the managed handles.

It relies on get_commands() and execute_command(), so you can change the behaviour by subclassing those methods.

get_commands()

This method reads a chunk of data from the input filehandle (via sysread) and tries to extract as many commands as possible from them.

In the current implementation, commands are line-oriented, so each fully formed line (i.e. up to the terminating newline) are considered commands. Actual command parsing and extraction is done via parse_command(), which can be overridden in derived classes.

This implementation is aligned to that in WWW::Slides::Client::Base, for a list and a description of the implemented commands see its documentation.

execute_command($command, $talk)

This method receives a $command and executes it on the talk $talk.

In the current implementation, $command is a hash reference containing at least the command key, which points to the command name to execute. This format is the same as the return value of parse_command().

parse_command($command_string)

This method accepts a command in textual form $command_string and emits a command suitable for execution by execute_command, i.e. a hash reference in the current implementation.

The input $command_string is currently considered a single input line, which is split on /\s;/ in a first pass and then on /=/ to extract key-value pairs which fill the output hash.

Note that the target parameter, if present, is split on /,/ and the resulting list is put into an anonymous array.

owns($filehandle)

Returns true if the $filehandle is managed by this object, false otherwise. For WS::Controller::Single object, this is equivalent to say that the object is still alive and $filehandle is equal to the input handle.

output(...)

Send output to the output handle, if set. The input list is passed to:

   $output_handle->print(...);

DIAGNOSTICS

Will complete this in the future...

Error message here, perhaps with %s placeholders

[Descrizione di un errore]

Another error message here

[Descrizione di un errore]

[E così via...]

CONFIGURATION AND ENVIRONMENT

WWW::Slides::Controller::Single requires no configuration files or environment variables.

DEPENDENCIES

None.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests through http://rt.cpan.org/

AUTHOR

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

LICENCE AND COPYRIGHT

Copyright (c) 2007, 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 itself. See perlartistic and perlgpl.

Questo modulo è software libero: potete ridistribuirlo e/o modificarlo negli stessi termini di Perl 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 350:

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