Acme-Pythonic
view release on metacpan or search on metacpan
747576777879808182838485868788899091929394
- 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.
- 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
789101112131415161718192021222324252627use
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
524525526527528529530531532533534535536537538539540541542543544545546547consumed 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
t/calculator.t view on Meta::CPAN
t/dangling.t view on Meta::CPAN
123456789101112# 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
12345678910111213141516# -*- Mode: Python -*-
use
warnings;
# ----------------------------------------------------------------------
my
$z
= 4
do
:
$z
*= 2
$z
+= 1
if
$z
== 4
is
$z
, 9
1234567891011121314# -*- Mode: Python -*-
use
warnings
# ----------------------------------------------------------------------
my
$sgn
= 1
for
my
$i
= 0;
$i
< 3; ++
$i
:
$sgn
*= -1
ok
$sgn
, -1
t/foreach.t view on Meta::CPAN
1234567891011121314# -*- Mode: Python -*-
# ----------------------------------------------------------------------
my
$sgn
= 1
foreach
my
$i
= 0;
$i
< 3; ++
$i
:
$sgn
*= -1
ok
$sgn
, -1
# ----------------------------------------------------------------------
123456789101112131415# -*- Mode: Python -*-
use
warnings;
# ----------------------------------------------------------------------
sub
foo:
my
$i
= \
7
return
$i
is foo, 7
1234567891011121314151617
1234567891011121314# -*- Model: Python -*-
use
strict
# ----------------------------------------------------------------------
my
$n
= 10
while
--
$n
:
pass
is
$n
, 0
t/subproto.t view on Meta::CPAN
t/text_wrap.t view on Meta::CPAN
456789101112131415161718192021222324252627282930313233343536373839404142#
# 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.
package
Acme::Pythonic::Text::Wrap
require
Exporter
@ISA
=
qw(Exporter)
@EXPORT
=
qw(wrap fill)
@EXPORT_OK
=
qw($columns $break $huge)
$VERSION
= 2001.09291
$separator)
use
strict
BEGIN:
$columns
= 76
# <= screen width
$debug
= 0
$break
=
'\s'
$huge
=
'wrap'
# alternatively: 'die' or 'overflow'
$unexpand
= 1
$tabstop
= 8
$separator
=
"\n"
sub
wrap:
my
(
$ip
,
$xp
,
@t
) =
@_
t/text_wrap.t view on Meta::CPAN
75767778798081828384858687888990919293949596979899100101102
die
"couldn't wrap '$t'"
else
:
die
"This shouldn't happen"
$lead
=
$xp
$ll
=
$nll
$nl
=
$separator
$r
.=
$remainder
"-----------$r---------\n"
if
$debug
"Finish up with '$lead'\n"
if
$debug
$r
.=
$lead
.
substr
(
$t
,
pos
(
$t
),
length
(
$t
)-
pos
(
$t
)) \
if
pos
(
$t
) ne
length
(
$t
)
"-----------$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
)):
( run in 0.407 second using v1.01-cache-2.11-cpan-8d75d55dd25 )