Acme-Text-Shorten-ForTwitter
view release on metacpan or search on metacpan
lib/Acme/Text/Shorten/ForTwitter.pm view on Meta::CPAN
print $shortener->shorten("I am happy to see you");
# I'm happy to see u
# Only load specific plugins:
use Acme::Text::Shorten::ForTwitter qw(+texting);
# Load all plugins except a few
use Acme::Text::Shorten::ForTwitter qw(-texting);
# Add a base rule
$shortener->add_rule('texting');
# Add a custom rule
$shortener->add_rule('/dev/null' => sub { my $text = shift; $$text = ''; });
# Remove a rule
$shortener->remove_rule('contractoins');
=head1 DESCRIPTION
This module makes writing content-rich tweets easier by helping
you shorten things as much as possible while still maintaining
the original content's meaning.
Various plugins are shipped with this module by default, and you
can write your own or install more from CPAN (if any are available.)
See L</"Writing Plugins"> below for information on writing plugins.
=head2 Class Methods
=head3 new
my $shortener = Acme::Text::Shorten::ForTwitter->new;
Creates a new shortener with all of the rules selected at
import time.
=head2 Object Methods
=head3 shorten
print $shortener->shorten("What is going on?");
Takes text as input and transforms it to a shorter version
if possible. It achieves this by running through all enabled
rules and attempting to apply them to the input.
=head3 add_rule
$shortener->add_rule("name");
$shortener->add_rule("name", sub {
my $text = shift; $$text =~ s/hello/hi/;
});
In the first form, adds a named rule from one of the loaded
plugins to the list of rules to use. Will die if the named
rule cannot be found.
In the second form, adds a custom rule. The subroutine should
take a reference to a scalar, and should modify the scalar
as needed.
=head3 remove_rule
$shortener->remove_rule("name");
Removes the named rule from the shortener. Will die if the named
rule cannot be found.
=head1 Writing Plugins
A plugin should look like this:
package Acme::Text::Shorten::ForTwitter::Plugin::MyPlugin;
use strict;
use warnings;
sub modify_base_rules {
my $pkg = shift;
my $base = shift;
$base->{rule_name} = sub {
my $text = shift;
$$text =~ s/\bsome long thing/some short thing\b/g;
};
return;
}
It will automatically be loaded when
L<Acme::Text::Shorten::ForTwitter> is loaded.
=head1 AUTHOR
Matthew Horsfall (alh) - <wolfsage@gmail.com>
=cut
( run in 0.630 second using v1.01-cache-2.11-cpan-39bf76dae61 )