Acme-CorpusScrambler

 view release on metacpan or  search on metacpan

lib/Acme/CorpusScrambler.pm  view on Meta::CPAN

package Acme::CorpusScrambler;

use warnings;
use strict;

use Text::Greeking::zh_TW;

=head1 NAME

Acme::CorpusScrambler - An Acme way doing Lorem Ipsum.

=head1 VERSION

version 0.04

=cut

our $VERSION = '0.04';

=head1 SYNOPSIS

    use Acme::CorpusScrambler;

    my $foo = Acme::CorpusScrambler->new();
    my $text = $foo->scramble;

=head1 FUNCTIONS

=head2 new

Object constructor, no parameters required.

=cut

sub new {
    my $class = shift;
    bless {}, $class;
}

=head2 feed( $keyword => $corpus )

Feeds the $corpus to object, indexed by $keyword. The corpus is used latter as scrambling
material.

=cut

my %corpushash;
sub feed {
    my ($self, $keyword, $corpus) = @_;
    $corpushash{"$keyword"}="$corpus";
    $self;
}

=head2 scramble( @keyword )

Generate a piece of lipsum text accroding to @keyword. If you didn't
feed any corpus before with feed() method, it will use
Text::Greeking::zh_TW's default corpus.

=cut

sub scramble {
    my ($self, @keyword) = @_;

    my $g = Text::Greeking::zh_TW->new;
    $g->paragraphs(3,15);
    $g->sentences(2,10);

    if (@keyword) {
        my $newcorpus = join("\n\n", @corpushash{ grep { exists $corpushash{$_} } @keyword });
        if ($newcorpus) {
            $g->add_source($newcorpus);
            return $g->generate;
        }
        return ""
    }else {
        return $g->generate;
    }
}

=head1 AUTHOR

Kang-min Liu <gugod at gugod.org>

shelling <navyblueshellingford at gmail.com>

=head1 BUGS

Please report any bugs or feature requests to C<shelling at cpan.org> or C<gugod at gugod.org>

=head1 SUPPORT



( run in 0.940 second using v1.01-cache-2.11-cpan-13bb782fe5a )