Acme-Laugh

 view release on metacpan or  search on metacpan

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

package Acme::Laugh;

use version; $VERSION = qv('0.0.5');

use warnings;
use strict;
use Carp;
use Exporter;

our @ISA = qw( Exporter );
our %EXPORT_TAGS = ('all' => [qw( laugh )]);
our @EXPORT_OK   = (@{$EXPORT_TAGS{'all'}});
our @EXPORT      = qw();

# Module implementation here

my @incipit = ('', qw( m b mb ));
my @alto    = qw( w u );
my @basso   = qw( a e );

=encoding iso-8859-1

=begin Private

=over

=item incipit()

Returns the incipit of the laugh. No parameters.

=item minichunk( $first );

Returns a chunk of a laugh. It is compound of one to three letters.
The input parameter forces the inclusion of the first letter, for reasons
too difficult to explain here.

=item continuum( $chunks );

Returns the join of a $chunks number of elements, where $chunks defaults
to 1 + rand 4;

=item capitals( $laugh );

Returns the input $laugh where some of the letters are capitalised in
a random fashion.

=back

=end Private

=cut

sub incipit { return $incipit[rand @incipit]; }

sub minichunk {
   my ($dopre) = @_;
   my $pre = $alto[rand @alto];
   $pre = '' if (!$dopre) && (rand > 0.5);
   my $post = (rand > 0.5) ? 'h' : '';
   my $chunk = join '', $pre, $basso[rand @basso], $post;
   return ($chunk, $post);
} ## end sub minichunk

sub continuum {
   my $chunks = shift || 0;
   $chunks = 1 + rand 4 if $chunks < 1;
   my $p = 0;
   return join '',
     map { (my $c, $p) = minichunk(!$p); $c; } 1 .. $chunks;
} ## end sub continuum

sub capitals {
   return join '', map { rand > 0.5 ? uc($_) : $_; } split //, shift;
}

sub laugh { return capitals(join '', incipit(), continuum(shift)); }

1;    # Magic true value required at end of module
__END__

=head1 NAME

Acme::Laugh - add joy to your scripts.


=head1 VERSION

This document describes Acme::Laugh version 0.0.1


=head1 SYNOPSIS

    use Acme::Laugh qw( laugh );

    print laugh(5);  # print a short laugh
    print laugh(50); # print a long laugh


=head1 DESCRIPTION

=for l'autore, da riempire:
   Fornite una descrizione completa del modulo e delle sue caratteristiche.
   Aiutatevi a strutturare il testo con le sottosezioni (=head2, =head3)
   se necessario.

Laughing is something that lets humans distinguish themselves from other
forms of life. Now computers are nearer to us :)

Have you ever needed to generate a laugh? I had: in IRC, to laugh at
other people (for fun!). So, here we are!

=head1 INTERFACE 

This module lets you export the C<laugh> function:

=over

=item my $l = laugh( $length ); 

=item my $l = laugh();  # Random length



( run in 1.335 second using v1.01-cache-2.11-cpan-5a3173703d6 )