Acme-Pythonic
view release on metacpan or search on metacpan
- Minor documentarion fixes.
- Added t/pass.t.
- The refactoring forgot "pass", restored (ugh, Test::More has a pass() that
made the tests compile an run!)
- The removal of some semicolons didn't work with trailing comments, fixed.
- Removed a comment that no longer applied.
0.23 Mon Jun 7 02:56:29 2004
- Port of the calculator example in Stroustrup's in t/calculator.t.
- Fixed: use constant HASHREF didn't get a semicolon.
- In debug mode blanked out chunks are substituted with
the label "BLANKED_OUT" for easy identification.
- The module got confused with newlines added by
Filter::Simple, fixed.
- Removed an old, no longer used subroutine.
0.22 Sat Jun 5 14:33:13 2004
- Just Re-uploaded. Changes was not saved in 0.21.
0.21 Sat Jun 5 14:30:32 2004
- Fixed a minor mistake in the POD.
lib/Acme/Pythonic.pm view on Meta::CPAN
use strict;
use warnings;
our ($VERSION, $DEBUG, $CALLER);
$VERSION = '0.47';
use Text::Tabs;
sub import {
my ($package, %cfg) = @_;
$DEBUG = $cfg{debug};
$CALLER = caller() # to be able to check sub prototypes
}
use Filter::Simple;
FILTER_ONLY code => sub {
unpythonize();
cuddle_elses_and_friends();
if ($DEBUG) {
s/$Filter::Simple::placeholder/BLANKED_OUT/g;
lib/Acme/Pythonic.pm view on Meta::CPAN
consumed in the compilation phase by then.
=head1 DEBUG
L<Filter::ExtractSource> can be used to inspect the source code
generated by Acme::Pythonic:
perl -c -MFilter::ExtractSource pythonic_script.pl
Acme::Pythonic itself has a C<debug> flag though:
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.
t/algorithms.t view on Meta::CPAN
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
use integer
# ----------------------------------------------------------------------
# $i ** $j (mod $n)
sub exp_mod:
my ($i, $j, $n) = @_
my $r = 1
while $j:
t/calculator.t view on Meta::CPAN
# -*- Mode: Python -*-
#
# --- [ A port of the calculator example in Stroustrup's ]--------------
#
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
use strict
use warnings
use vars qw($cin $curr_tok $number_value $string_value %table)
use constant NAME => 0
use constant NUMBER => 1
use constant STOP => 2 # END is a Perl keyword
use constant PLUS => '+'
t/dangling.t view on Meta::CPAN
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# This checks whether the stack gets emptied. If it is not it does not
# compile.
# It's important that this file ends in the ok 1 line.
no warnings
if 1:
unless 0:
$n = 0
# -*- Mode: Python -*-
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my $z = 4
do:
$z *= 2
$z += 1
if $z == 4
is $z, 9
# -*- Mode: Python -*-
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
use warnings
# ----------------------------------------------------------------------
my $sgn = 1
for my $i = 0; $i < 3; ++$i:
$sgn *= -1
ok $sgn, -1
t/foreach.t view on Meta::CPAN
# -*- Mode: Python -*-
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my $sgn = 1
foreach my $i = 0; $i < 3; ++$i:
$sgn *= -1
ok $sgn, -1
# ----------------------------------------------------------------------
# -*- Mode: Python -*-
# These are Pythonic ports of programs from MJD's HOP.
# Acme::Pythonic needs to know this prototype.
sub Iterator(&);
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
use strict
use warnings
my ($it, $computed, $expected)
#
# ---[ Chapter 1: Recursion ]-------------------------------------------
#
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my $x = 1
if $x:
$x += 1
$x *= 3
is($x, 6)
# -*- Mode: Python -*-
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
sub foo:
my $i = \
7
return $i
is foo, 7
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my @lines = ("foo\n", "bar\n", "baz\n")
LINE: foreach my $line in @lines:
chomp $line
if $line eq "bar":
last LINE
is_deeply(\@lines, ["foo", "bar", "baz\n"]) # in the same line
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my @foo = 1..5
@foo = map:
$_ *= 2
$_ += 1
@foo
is_deeply \@foo, [3, 5, 7, 9, 11]
# -*- Model: Python -*-
use Test::More tests => 4, import => ['is'];
use Acme::Pythonic debug => 0;
use strict
# ----------------------------------------------------------------------
my $n = 10
while --$n:
pass
is $n, 0
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
sub foo:
my $i = 7
return $i
is foo, 7
# ----------------------------------------------------------------------
t/subproto.t view on Meta::CPAN
# -*- Mode: Python -*-
use warnings;
package Foo;
sub bar (&);
sub foo (&);
sub twice (&);
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
sub mygrep (&@):
my $code = shift
my @result
foreach @_:
push @result, $_ if &$code
return @result
t/text_wrap.t view on Meta::CPAN
#
# 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
@ISA = qw(Exporter)
@EXPORT = qw(wrap fill)
@EXPORT_OK = qw($columns $break $huge)
$VERSION = 2001.09291
use vars qw($VERSION $columns $debug $break $huge $unexpand $tabstop
$separator)
use strict
BEGIN:
$columns = 76 # <= screen width
$debug = 0
$break = '\s'
$huge = 'wrap' # alternatively: 'die' or 'overflow'
$unexpand = 1
$tabstop = 8
$separator = "\n"
use Text::Tabs qw(expand unexpand)
sub wrap:
my ($ip, $xp, @t) = @_
t/text_wrap.t view on Meta::CPAN
die "couldn't wrap '$t'"
else:
die "This shouldn't happen"
$lead = $xp
$ll = $nll
$nl = $separator
$r .= $remainder
print "-----------$r---------\n" if $debug
print "Finish up with '$lead'\n" if $debug
$r .= $lead . substr($t, pos($t), length($t)-pos($t)) \
if pos($t) ne length($t)
print "-----------$r---------\n" if $debug
return $r
sub fill:
my ($ip, $xp, @raw) = @_
my @para
my $pp
for $pp in split(/\n\s+/, join("\n",@raw)):
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my $x = 1
unless $x:
$x += 1
$x *= 3
is($x, 1)
# -*- Mode: Python -*-
use strict;
use warnings;
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
# ----------------------------------------------------------------------
my $x = 10
while $x--:
pass
is $x, -1
# ----------------------------------------------------------------------
( run in 0.968 second using v1.01-cache-2.11-cpan-87723dcf8b7 )