Acme-Pythonic

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.03 Mon May 24 23:36:55 2004
    - More tests
    - pass wasn't being ignored at the beginning of line
    - Fixed a bug handling fors
    - More documentation fixes

0.02 Mon May 24 15:31:42 2004
	- Minor fixes in documentation

0.01  Mon May 17 23:14:00 2004
	- original version; created by h2xs 1.23 with options
		-XA -n Acme::Pythonic

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

sub left_parenthesize {
    $_[0] =~ s/^(\s*\b(?:if|elsif|unless)\b\s*)/$1(/                                      ||
    $_[0] =~ s/^(\s*(?:$id\s*:)?\s*\b(?:while|until)\b(\s*))/$2 eq '' ? "$1 (" : "$1("/eo ||
    $_[0] =~ s/^(\s*(?:$id\s*:\s*)?\bfor(?:each)?\b\s*)(.*)/fortype_guesser($1,$2)/oxe
}


# Tries its best at guessing a for(each) type or, at least, where to put
# the opening paren.
#
# Returns a string which is a copy of the original with the paren
# inserted.
sub fortype_guesser {
    my ($for, $rest) = @_;
    my $guess = "";

    # Try to match "for VAR in LIST", and "for VAR LIST"
    if ($rest =~ m/^((?:my|our)? \s* \$ $id\s+) in\s* ((?: (?:[\$\@%&\\]) | (?:\b\w) ) .*)$/ox ||
        $rest =~ m/^((?:my|our)? \s* \$ $id\s*)       ((?: (?:[\$\@%&\\]) | (?:\b\w) ) .*)$/ox) {
        $guess = "$for$1($2";
    } else {

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

    use Acme::Pythonic debug => 1;

In debug mode the module prints to standard output the code it has
generated, and passes just a dummy C<1;> to L<Filter::Simple>.

This happens I<before> L<Filter::Simple> undoes the blanking out of
PODs, strings, and regexps. Those parts are marked with the label
C<BLANKED_OUT> for easy identification.

Acme::Pythonic generates human readable Perl following L<perlstyle>, and
tries meticulously to be respectful with the original source code.
Blank lines and comments are preserved.


=head1 BUGS

This module uses a regexp approach and the superb help of
Filter::Simple. The regexp part of this means it is broken from the
start, though I've tried hard to make it as robust as I could. Bug
reports will be very welcome, just drop me a line!

t/text_wrap.t  view on Meta::CPAN

# -*- Mode: Python -*-

# This is a meticolous port of Text::Wrap.
#
# The intention is to test whether an example of real code is processed
# correctly.
#
# It has been written by copying the original code and doing the minimal
# changes for it to be Pythonic, which means colonizing, removing some
# parens, adding a few backslashes, etc. Comments, spacing, and all
# details have been kept.

use Test::More 'no_plan';
use Acme::Pythonic debug => 0;

package Acme::Pythonic::Text::Wrap

require Exporter



( run in 0.499 second using v1.01-cache-2.11-cpan-1c8d708658b )