Data::Text - Class to handle text in an OO way
Version 0.12
Handle text in an OO way.
use Data::Text; my $d = Data::Text->new("Hello, World!\n"); print $d->as_string();
Creates a Data::Text object.
The optional parameter contains a string, or object, to initialise the object with.
Sets the object to contain the given text.
The argument can be a reference to an array of strings, or an object. If called with an object, the message as_string() is sent to it for its contents.
$d->set({ text => "Hello, World!\n" }); $d->set(text => [ 'Hello, ', 'World!', "\n" ]);
Adds data given in "text" to the end of the object. Contains a simple sanity test for consecutive punctuation. I expect I'll improve that.
Successive calls to append() can be daisy chained.
$d->set('Hello ')->append("World!\n");
Are two texts the same?
my $t1 = Data::Text->new('word'); my $t2 = Data::Text->new('word'); print ($t1 == $t2), "\n"; # Prints 1
Are two texts different?
my $t1 = Data::Text->new('xyzzy'); my $t2 = Data::Text->new('plugh'); print ($t1 != $t2), "\n"; # Prints 1
Returns the text as a string.
Returns the length of the text.
Removes leading and trailing spaces from the text.
Removes trailing spaces from the text.
Replaces words.
use Data::Text; my $dt = Data::Text->new(); $dt->append('Hello World'); $dt->replace({ 'Hello' => 'Goodbye dear' }); print $dt->as_string(), "\n"; # Outputs "Goodbye dear world"
Nigel Horne, <njh at bandsman.co.uk>
<njh at bandsman.co.uk>
String::Clean, String::Util
You can find documentation for this module with the perldoc command.
perldoc Data::Text
You can also look for information at:
MetaCPAN
https://metacpan.org/release/Data-Text
RT: CPAN's request tracker
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Text
CPAN Testers' Matrix
http://matrix.cpantesters.org/?dist=Data-Text
CPAN Ratings
http://cpanratings.perl.org/d/Data-Text
CPAN Testers Dependencies
http://deps.cpantesters.org/?module=Data::Text
Copyright 2021-2022 Nigel Horne.
This program is released under the following licence: GPL2
To install Data::Text, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Text
CPAN shell
perl -MCPAN -e shell install Data::Text
For more information on module installation, please visit the detailed CPAN module installation guide.