Acme-Playwright

 view release on metacpan or  search on metacpan

Playwright.pm  view on Meta::CPAN


@pS = (
    'I think you broke it.',          'It just needs new batteries.',
    'How long have you known?',       'I wish I could fly.',
    'At night the ice weasles come.', 'The penguins are tearing at my flesh.',
    "You think I'm dumb, don't you?", "I've never been so insulted.",
    'Sure is windy out there.',       'Do you smell smoke?'
);

@pT = (
    'You should try it sometime.', "I don't think I'd like that.",
    'Kiss me.',                    'Do you need a tissue?',
    'Good question.',              'What an ugly cat!',
    'Want to hear a joke?',        'Not if you are the one doing it.',
    'It sure is a long way down.', 'How long did it take to make that?'
);

while ( ( $name, $val ) = each %Names ) {
    $rNames{ $val } = $name;
}

while ( ( $name, $val ) = each %Phrases ) {
    $rPhrases{ $val } = $name;
}

@Names = keys %Names;

@Actions = (
    'writes a poem',                            'enters from stage left',
    "peers over Michael's shoulder",            'laughs',
    'screams in pain',                          'opens a book',
    'sits at the table',                        'crosses stage right',
    'looks under the chair',                    'straightens the table cloth',
    'opens the window',                         'looks around in confusion',
    'starts singing quietly',                   'closes the window',
    'cries',                                    'enters from stage right',
    'crosses stage left',                       'picks up the book',
    'breaks the mirror',                        'kicks the table',
    'gazes longingly at Pietro',                'dances a merry jig',
    'thinks happy thoughts',                    'falls to the floor',
    'tries to think of something funny to say', 'yearns for the good old days',
    'turns on the radio',                       'turns off the radio',
    'turns on the television',                  'turns off the television',
    'selects a book from the bookshelf',        'concentrates',
    'burps',                                    'clucks like a chicken',
    'motions toward the door',                  'plops down on the sofa',
    'looks around suspiciously',                'beings folding laundry',
    'takes a pan of brownies from the oven',    'thinks of the color blue',
    "pours vinegar in Karen's shoes",           'eats a pickle',
    'disrobes',                                 'dances about like a loon',
    'flits about like a fawn in springtime',    'does an impression of Charlie Chaplin',
    'takes a ham from the oven',                'begins plucking a chicken',
    'tries to hide under the rug',              'removes the cushions from the sofa',
    'opens the pantry',                         'climbs in the pantry',
    'crawls under the sink',                    'closes the pantry',
    'fixes a turkey sandwich',                  'starts making pancakes'
);

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

sub RandomElement {
    shift if UNIVERSAL::isa( $_[ 0 ], __PACKAGE__ );
    my $arrayref = shift;
    $arrayref->[ rand @{ $arrayref } ];
}

sub StageDirections {
    shift if UNIVERSAL::isa( $_[ 0 ], __PACKAGE__ );
    return $Delimiter{ 'left' } . RandomElement( \@Names ) . " " . RandomElement( \@Actions ) . $Delimiter{ 'right' } . "\n";
}

sub Make {
    shift if UNIVERSAL::isa( $_[ 0 ], __PACKAGE__ );
    my $string = shift;
    my @chars = split ( //, $string );
    my ( $out, $i, $temp );
    for ( $i = 0 ; $i <= $#chars ; $i += 2 ) {
        if ( $chars[ $i ] eq "\n" ) {
            $out .= StageDirections();
            $i--;
            next;
        } elsif ( $chars[ $i ] eq " " ) {
            $temp = RandomElement( \@nSpace ) . ":";
        } elsif ( $chars[ $i ] eq "a" ) {
            $temp = RandomElement( \@nA ) . ":";
        } elsif ( $chars[ $i ] eq "e" ) {
            $temp = RandomElement( \@nE ) . ":";
        } elsif ( $chars[ $i ] eq "n" ) {
            $temp = RandomElement( \@nN ) . ":";
        } elsif ( $chars[ $i ] eq "o" ) {
            $temp = RandomElement( \@nO ) . ":";
        } elsif ( $chars[ $i ] eq "r" ) {
            $temp = RandomElement( \@nR ) . ":";
        } elsif ( $chars[ $i ] eq "s" ) {
            $temp = RandomElement( \@nS ) . ":";
        } elsif ( $chars[ $i ] eq "t" ) {
            $temp = RandomElement( \@nT ) . ":";
        } else {
            $temp = "$rNames{ $chars[ $i ] }:";
        }
        if ( ( $i + 1 ) > $#chars || $chars[ $i + 1 ] eq "\n" ) {
            $out .= $temp . " " . RandomElement( \@pSpace ) . "\n" . StageDirections();
            next;
        } elsif ( $chars[ $i + 1 ] eq " " ) {
            $temp .= " " . RandomElement( \@pSpace );
        } elsif ( $chars[ $i + 1 ] eq "a" ) {
            $temp .= " " . RandomElement( \@pA );
        } elsif ( $chars[ $i + 1 ] eq "e" ) {
            $temp .= " " . RandomElement( \@pE );
        } elsif ( $chars[ $i + 1 ] eq "n" ) {
            $temp .= " " . RandomElement( \@pN );
        } elsif ( $chars[ $i + 1 ] eq "o" ) {
            $temp .= " " . RandomElement( \@pO );
        } elsif ( $chars[ $i + 1 ] eq "r" ) {
            $temp .= " " . RandomElement( \@pR );
        } elsif ( $chars[ $i + 1 ] eq "s" ) {
            $temp .= " " . RandomElement( \@pS );



( run in 1.988 second using v1.01-cache-2.11-cpan-39bf76dae61 )