Text::Translate::Format - basic format conversions for Text::Translate
version 0.1.0_01
my $obj = Text::Translate::Format->new( Pod => filename => '/opt/perl-5.12.2/lib/5.12.2/pod/perlfunc.pod' ); my @paragraphs = $obj->paragraphs(); my @translated = translate(@paragraphs); my $trans_obj = Text::Translate::Format->new( Pod => paragraphs => \@translated ); print "Translated POD:\n", $trans_obj->text();
This module allows transforming a text into paragraphs (suitable for handling through <L/Text::Translate>) and vice-versa. This module is actually a base class for format-specific subclasses, and acts as a factory to generate objects of these subclasses as well.
The typical life cycle will be the following:
load the source text from a file (or from a filehandle, or directly from a scalar variable):
my $src = Text::Translate::Format->new( Pod => filename => '/path/to/file.pod' );
get the paragraphs:
my @src_paragraphs = $src->paragraphs();
translate the paragraphs:
my @dst_paragraphs = translate(@src_paragraphs);
create an object for the translated document:
my $dst = Text::Translate::Format->new( Pod => paragraphs => \@dst_paragraphs );
get the textual rendition, e.g. for saving it or displaying:
my $translated = $dst->text(); print "Translated text:\n", $translated;
$obj->init(%args);
Object method.
(re)-initialise the object. You can pass one (and only one) of the following parameters in the %args:
%args
text
the text to be converted into paragraphs;
filename
the name of a file containing the text to convert into paragraphs;
paragraphs
an array reference to the ordered list of paragraphs.
You can pass a reference to a hash instead of a hash.
Returns the input $obj.
$obj
Text::Translate::Format::Whatever->new(%args);
Class method, to be called on derived classes (croaks when called on Text::Translate::Format).
Accepts the same arguments as "init".
Returns a reference to the new object.
Text::Translate::Format->create($format => %args)
Class method, to be called on the Text::Translate::Format class (by default, croaks when called in derived classes).
This is a factory method to generate an object of the right $format.
$format
Apart from the first parameter - that represents the format - all the following parameters are the same as "init".
Returns a reference to the newly created object.
# setter $obj->paragraphs(@paragraphs); $obj->paragraphs(\@pars); # getter my @paragraphs = $obj->paragraphs(); my $ref_to_pars = $obj->paragraphs();
Object method, can be used as both a setter and a getter.
This method allows setting or getting the list of paragraphs.
If there are input parameters, they are set as the paragraphs list. It can be either a straight list, or a reference to an array containing the list.
Always returns the current list of paragraphs (in the setter case, returns the newly set list) in list context, a reference to an anonymous array containing the list in scalar context.
# setter $obj->text($text); # getter my $text = $obj->text();
This method allows setting or getting a text rendition of the paragraphs.
If there is an input parameter, it is considered as the text to be set.
Always returns the current text (i.e. the newly set text in case of the setter).
# Can pass either a filename or an open filehandle to read from my $text = $obj->text_from_file($filename); my $text = $obj->text_from_file($FILEHANDLE);
This method allows setting the text rendition of the paragraphs, reading it from either a file (provided through its filename) or from a filehandle.
Accepts either a filehandle or a filename.
Returns the text read from the file and set as "text".
$obj->paragraphs_to_text();
This method MUST be overridden in the derived classes; it takes the list of paragraphs (via "paragraphs") and generate the textual rendition (setting it through "text").
$obj->text_to_paragraphs();
This method MUST be overridden in the derived classes; it takes the textual representation (via "text") and generates the list of paragraphs (setting it through "paragraphs").
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2010 by Flavio Poletti.
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Text::Translate::Format, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Translate::Format
CPAN shell
perl -MCPAN -e shell install Text::Translate::Format
For more information on module installation, please visit the detailed CPAN module installation guide.