Acme-Pythonic
view release on metacpan or search on metacpan
MANIFEST
README
t/jlines.t
t/dangling.t
t/do.t
t/eval.t
t/for.t
t/foreach.t
t/if.t
t/labels.t
t/map.t
t/noindent.t
t/pass.t
t/pod.t
t/pod-coverage.t
t/sub.t
t/subproto.t
t/text_wrap.t
t/unless.t
t/until.t
t/use.t
lib/Acme/Pythonic.pm view on Meta::CPAN
}
if ($line =~ /(?:,|=>)\s*$/ || $line =~ s/\\\s*$//) {
++$joining;
next if $joining > 1; # if 1 we need yet to handle indentation
} else {
$joining = 0;
}
# Handle trailing colons, which can be Pythonic, mark a labeled
# block, mean some map, or &-sub call, etc.
#
# We check the parity of the number of ending colons to try to
# avoid breaking things like
#
# print for keys %main::
#
my $bracket_opened_by = '';
if ($line =~ /(:+)$/ && length($1) % 2) {
$might_be_modifier = 0;
# We perform some checks because labels have to keep their colon.
# Defined on page 122
sub NEXTVAL:
$_[0]->()
# Defined on page 123
sub Iterator(&):
return $_[0]
# Defined on page 160
sub imap(&$):
my ($transform, $it) = @_
return Iterator:
local $_ = NEXTVAL($it)
return unless defined $_
return $transform->()
$it = imap:
$_ *= 2
$_ += 1
$_
upto(2, 5)
$expected = [5, 7, 9, 11]
$computed = []
while my $val = NEXTVAL($it):
push @$computed, $val
is_deeply $expected, $computed
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]
# ----------------------------------------------------------------------
my %foo = (bar => 3,
baz => 2, # this comment shouldn't be a problem
moo => 4,
zoo => 1)
my @st = map:
$_->[0]
sort:
$a->[1] <=> $b->[1]
map:
[$_, $foo{$_}]
keys %foo
is_deeply \@st, [qw(zoo baz bar moo)]
# ----------------------------------------------------------------------
my %n = map { $_ => 1 } 1..5
my @n = grep:
my $aux = $_
$aux *= 2
$aux % 3
sort keys %n
is_deeply \@n, [1, 2, 4, 5]
t/text_wrap.t view on Meta::CPAN
$separator = "\n"
use Text::Tabs qw(expand unexpand)
sub wrap:
my ($ip, $xp, @t) = @_
local($Text::Tabs::tabstop) = $tabstop
my $r = ""
my $tail = pop(@t)
my $t = expand(join("", (map { /\s+\z/ ? ( $_ ) : ($_, ' ') } @t), $tail))
my $lead = $ip
my $ll = $columns - length(expand($ip)) - 1
$ll = 0 if $ll < 0
my $nll = $columns - length(expand($xp)) - 1
my $nl = ""
my $remainder = ""
use re 'taint'
pos($t) = 0
( run in 1.035 second using v1.01-cache-2.11-cpan-49f99fa48dc )