Acme-Pythonic

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    - 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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use strict;
 
our ($VERSION, $DEBUG, $CALLER);
$VERSION = '0.47';
 
 
sub import {
    my ($package, %cfg) = @_;
    $DEBUG = $cfg{debug};
    $CALLER = caller() # to be able to check sub prototypes
}
 
 
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

524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- Mode: Python -*-
 
use strict;
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
 
# ----------------------------------------------------------------------
 
# $i ** $j (mod $n)
sub exp_mod:
    my ($i, $j, $n) = @_
    my $r = 1
    while $j:

t/calculator.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- Mode: Python -*-
 
#
# --- [ A port of the calculator example in Stroustrup's ]--------------
#
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
use strict
 
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

1
2
3
4
5
6
7
8
9
10
11
12
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

t/do.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# -*- Mode: Python -*-
 
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
# ----------------------------------------------------------------------
 
my $z = 4
do:
    $z *= 2
    $z += 1
if $z == 4
 
is $z, 9

t/for.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- Mode: Python -*-
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
 
# ----------------------------------------------------------------------
 
my $sgn = 1
for my $i = 0; $i < 3; ++$i:
    $sgn *= -1
 
ok $sgn, -1

t/foreach.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- 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
 
# ----------------------------------------------------------------------

t/hop.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- 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
 
my ($it, $computed, $expected)
 
 
#
# ---[ Chapter 1: Recursion ]-------------------------------------------
#

t/if.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# -*- Mode: Python -*-
 
use strict;
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
# ----------------------------------------------------------------------
 
my $x = 1
if $x:
    $x += 1
    $x *= 3
 
is($x, 6)

t/jlines.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# -*- Mode: Python -*-
 
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
# ----------------------------------------------------------------------
 
sub foo:
    my $i = \
       7
    return $i
 
is foo, 7

t/labels.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- Mode: Python -*-
 
use strict;
 
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

t/map.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- Mode: Python -*-
 
use strict;
 
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]

t/pass.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- 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

t/sub.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- Mode: Python -*-
 
use strict;
 
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# -*- Mode: Python -*-
 
 
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

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#
# 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;
 
 
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

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
            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)):

t/unless.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# -*- Mode: Python -*-
 
use strict;
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
# ----------------------------------------------------------------------
 
my $x = 1
unless $x:
    $x += 1
    $x *= 3
 
is($x, 1)

t/while.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- Mode: Python -*-
 
use strict;
 
use Test::More 'no_plan';
use Acme::Pythonic debug => 0;
 
# ----------------------------------------------------------------------
 
my $x = 10
while $x--:
    pass
 
is $x, -1
 
# ----------------------------------------------------------------------



( run in 0.407 second using v1.01-cache-2.11-cpan-8d75d55dd25 )