POE-Component-IRC-PluginBundle-WebDevelopment
view release on metacpan or search on metacpan
lib/POE/Component/IRC/Plugin/WWW/Lipsum.pm view on Meta::CPAN
);
}
sub _make_response_message {
my ( $self, $in_ref ) = @_;
if ( $in_ref->{error} ) {
return [ $in_ref->{error} ];
}
my $text = join ' ', @{ $in_ref->{lipsum} };
$text =~ s/\s+/ /g;
my $line_max_length = $self->{line_lengths}{ $in_ref->{_type} } || 350;
while ( length( $text ) > $line_max_length ) {
push @{ $in_ref->{out} }, substr $text, 0, $line_max_length;
$text = substr $text, $line_max_length;
}
push @{ $in_ref->{out} }, $text;
my $line_num_max = $self->{max_lines}{ $in_ref->{_type} };
unless ( defined $line_num_max ) {
if ( $in_ref->{_type} eq 'public' ) {
$line_num_max = 1;
}
else {
$line_num_max = 5;
}
}
@{ $in_ref->{out} } = splice @{ $in_ref->{out} }, 0, $line_num_max;
return $in_ref->{out};
}
sub _make_response_event {
my $self = shift;
my $in_ref = shift;
return {
lipsum => $in_ref->{lipsum},
( exists $in_ref->{error}
? ( error => $in_ref->{error} )
: ( out => $in_ref->{out}, )
),
map { $_ => $in_ref->{"_$_"} }
qw( who channel message type what ),
}
}
sub _make_poco_call {
my $self = shift;
my $data_ref = shift;
my %args;
@args{ qw/amount what start html/ }
= map lc, split m|[/\s,]+|, $data_ref->{what};
$args{what} ||= 'words';
$args{amount} ||= '15';
if ( defined $args{html} and $args{html} =~ /yes/ ) {
$args{html} = 1
}
else {
delete $args{html};
}
my %max_amount_for = (
words => 7000,
paras => 100,
lists => 100,
bytes => 56000,
);
if ( $args{amount} > $max_amount_for{ $args{what} } ) {
$args{amount} = $max_amount_for{ $args{what} };
}
$self->{poco}->generate( {
event => '_poco_done',
args => \%args,
map +( "_$_" => $data_ref->{$_} ),
keys %$data_ref,
}
);
}
1;
__END__
=encoding utf8
=for stopwords Ipsum Lorem amet bot dolor ipsum privmsg regexen usermask usermasks
=head1 NAME
POE::Component::IRC::Plugin::WWW::Lipsum - plugin to generate Lorem Ipsum text in IRC
=head1 SYNOPSIS
use strict;
use warnings;
use POE qw(Component::IRC Component::IRC::Plugin::WWW::Lipsum);
my $irc = POE::Component::IRC->spawn(
nick => 'LipsumBot',
server => 'irc.freenode.net',
port => 6667,
ircname => 'Lorem Ipsum Bot',
plugin_debug => 1,
);
POE::Session->create(
package_states => [
( run in 2.085 seconds using v1.01-cache-2.11-cpan-71847e10f99 )