Poem - Don't let Perl stand in poets' way!


Poem documentation Contained in the Poem distribution.

Index


Code Index:

NAME

Top

Poem - Don't let Perl stand in poets' way!

SYNOPSIS

Top

  use Poem;
  Just Another Perl Poet
  no Poem; # get back to work

DESCRIPTION

Top

This module practically make perl accept any poem in any language. Yes, I mean any language. It even accepts poems in Unicode!

Options

Without import options, it prints your poem.

  use Poem;
  There are more than one way to Do it. -- Larry Wall
  no Poem;

-review

But you can let perl review your poem via -review.

  use Poem qw/-review/;
  There are more than one way to Do it. -- Larry Wall
  no Poem;

-strict

With this option stricture will apply.

  # this works
  use Poem qw/-review/;
  $Perl = "Practical Extractaction and Report Language";
  no Poem;

  # but not under stricture
  use Poem qw/-review -strict/;
  $Perl = "Pathologically Eclectic Rubbish Lister";
  no Poem;

-deparse

If you don't grok your own poem, let perl deparse it.

  # Let perl deparse it
  use Poem qw/-review -deparse/;
  Just Another Perl Poet
  no Poem;

-act

If you are an activist rather an a poet, this optin is for you.

  # Who said talk is cheap?
  use Poem qw/-review -act/;
  Just Another Perl Poet
  no Poem;

-utf8

Even if your poem is written in non-ascii, Poem works. But if you want perl to review it, you probably need this option as well. See t/unicode.pl to find out what I mean.

-quiet

This is a no-op. Consider that a poet's way of saying =pod - =cut

  use Poem -quiet;
  Just Another Perl Poet
  no Poem;

EXPORT

None by default.

SEE ALSO

Top

Filter::Util::Call

AUTHOR

Top

Dan Kogai, <dankogai@dan.co.jp>

COPYRIGHT AND LICENSE

Top


Poem documentation Contained in the Poem distribution.

#
# $Id: Poem.pm,v 0.1 2006/03/25 10:43:27 dankogai Exp dankogai $
#
package Poem;
use 5.008001;
use strict;
use warnings;
our $VERSION = sprintf "%d.%02d", q$Revision: 0.1 $ =~ /(\d+)/g;

use Filter::Util::Call;
my %opt = ();
sub import{
    my $class = shift;
    %opt = map { $_ => 1 } @_;
    filter_add(\&read_poem);
}
sub unimport{
    my $class = shift;
    filter_del();
    %opt = ();
}
sub read_poem{
    my $pkg = __PACKAGE__; 
    my ($status, $no_seen, @poem);
    while ($status = filter_read()) {
	if (/^\s*no\s+$pkg\s*;\s*?$/) {
	    $no_seen=1;
	    last;
	}
	push @poem, $_;
	$_ = q();
    }
    if ($opt{-review}){
	# eval does not work in filter.  So we ask via pipe
	print "# Your Poem:\n";
	print @poem;
	my $perlopt = 
	    $opt{-deparse} ? "-MO=Deparse" :
	    $opt{-act} ? '-T' : '-Twc';
	print "# Review by $^X $perlopt\n";
	open my $perl, "| $^X $perlopt 2>&1" or die "$!";
	$opt{-strict} and print $perl "use strict;\n";
	$opt{-utf8}   and print $perl "use utf8;\n";
	print $perl @poem;
	close $perl;
    }else{
	print @poem unless $opt{-quiet};
    }
    if ($no_seen){
	$_ .= "no $pkg;\n";
	return 1;
    }else{
	return 0;
    }
}

# Preloaded methods go here.

1;
__END__
# Below is stub documentation for your module. You'd better edit it!