line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl6::Feeds;
|
2
|
|
|
|
|
|
|
require 5.009_005;
|
3
|
2
|
|
|
2
|
|
49067
|
use strict;
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
73
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
57
|
|
5
|
2
|
|
|
2
|
|
3386
|
use Filter::Simple;
|
|
2
|
|
|
|
|
117390
|
|
|
2
|
|
|
|
|
20
|
|
6
|
2
|
|
|
2
|
|
115
|
use re 'eval';
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
440
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.20';
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
FILTER_ONLY code => sub {
|
10
|
|
|
|
|
|
|
s/(?
|
11
|
|
|
|
|
|
|
my $nested = qr/ (
|
12
|
|
|
|
|
|
|
( [{[(] )
|
13
|
|
|
|
|
|
|
(?: [^{}[\]()]++ | (?-2) )*
|
14
|
|
|
|
|
|
|
(??{ '\\'.{qw'{ } [ ] ( )'}->{$^N} })
|
15
|
|
|
|
|
|
|
) /x;
|
16
|
|
|
|
|
|
|
my $expression = qr/ (?: $nested | [^;{}[\]()] )+? /x;
|
17
|
|
|
|
|
|
|
1 while s{
|
18
|
|
|
|
|
|
|
(?: ^ | (?<= [\{[(;] ) )
|
19
|
|
|
|
|
|
|
\s*
|
20
|
|
|
|
|
|
|
(? |
21
|
|
|
|
|
|
|
\s* ==+>(? >?+ )(? [<>]?+ ) \s*
|
22
|
|
|
|
|
|
|
(? $expression )
|
23
|
|
|
|
|
|
|
\s*
|
24
|
|
|
|
|
|
|
(?= ==+>+ | [\}\]);] | $ )
|
25
|
|
|
|
|
|
|
}{
|
26
|
|
|
|
|
|
|
'sub{@_}->(' . do {
|
27
|
2
|
|
|
2
|
|
1904
|
my ($source, $action) = @+{qw/source action/};
|
|
2
|
|
|
|
|
1150
|
|
|
2
|
|
|
|
|
507
|
|
28
|
|
|
|
|
|
|
$+{merge} eq '<' and "($action), ($source)" or
|
29
|
|
|
|
|
|
|
$+{merge} eq '>' and "($source), ($action)" or do {
|
30
|
|
|
|
|
|
|
for ($action) {
|
31
|
|
|
|
|
|
|
$action = "push $_,", last if $+{push};
|
32
|
|
|
|
|
|
|
$action .= '=', last if /^(?:(?:my|our|local)\W|[$@%&*])/;
|
33
|
|
|
|
|
|
|
$source = ",$source" unless /^\w+\s*(?:(?=\{)$nested)?$/;
|
34
|
|
|
|
|
|
|
$source .= ')' if s/\)$//;
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
"$action $source"
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
} . ')'
|
39
|
|
|
|
|
|
|
}xse
|
40
|
|
|
|
|
|
|
};
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Perl6::Feeds - implements perl6 feed operators in perl5 via source filtering
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 VERSION
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
version 0.20
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
requires perl version 5.9.5 or higher
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
this code is currently in beta, bug reports welcome
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
feed operators allow you to write expressions that flow left to right and top down,
|
57
|
|
|
|
|
|
|
rather than the right to left, bottom up order imposed by function nesting.
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use Perl6::Feeds;
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1..10 ==> map {$_**2} ==> grep {$_>10} ==> join " " ==> print;
|
62
|
|
|
|
|
|
|
# is the same as
|
63
|
|
|
|
|
|
|
print join " " => grep {$_>10} map {$_**2} 1..10;
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1 .. 3000
|
66
|
|
|
|
|
|
|
==> map [$_, $_ ** 2 ]
|
67
|
|
|
|
|
|
|
==> grep {$$_[1] =~ s/(([^0])\2{3,})/ ($1) /g}
|
68
|
|
|
|
|
|
|
==> our @list # assignments start with /my|our|local|[$@%&*]/
|
69
|
|
|
|
|
|
|
==> map {@$_ ==> map "[$_]" # nesting is fine
|
70
|
|
|
|
|
|
|
==> join '^2 ==> '} # strings are safe
|
71
|
|
|
|
|
|
|
==>>> 'found '.@list.' numbers: ' # appends a list
|
72
|
|
|
|
|
|
|
==>>< "\nnumbers with squares that ". # prepends a list
|
73
|
|
|
|
|
|
|
"have non zero runs of 4+ digits:\n" # both of these are not in the perl6 spec
|
74
|
|
|
|
|
|
|
==> join ("\n") # closed argument lists are adjusted
|
75
|
|
|
|
|
|
|
==>>> (@list ==> map $$_[0] ==> join ' ')
|
76
|
|
|
|
|
|
|
=====> print; # feed arrows match /==+>[<>]?/
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNTAX
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1 .. 10 ==> join ", " ==> print; # print join ", " => 1 .. 10;
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1 .. 10 ==> my @a; # my @a = 1 .. 10;
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
20 .. 30 ==>> @a; # push @a, 20 .. 30;
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
@a ==>>> "appended" ==> print; # print @a, "appended";
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
@a ==>>< "prepended" ==> print; # print "prepended", @a;
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Eric Strom, C<< >>
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 BUGS
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
currently, only left to right feeds are supported, and there may be a few corner cases that
|
97
|
|
|
|
|
|
|
the filter will fail on.
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
bug reports or patches welcome, send them to C, or through the
|
100
|
|
|
|
|
|
|
web interface at L. I will be
|
101
|
|
|
|
|
|
|
notified, and then you'll automatically be notified of progress on your bug as I make changes.
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
the perl6 synopsi
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
copyright 2009 Eric Strom.
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
this program is free software; you can redistribute it and/or modify it
|
112
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published
|
113
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License.
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
see http://dev.perl.org/licenses/ for more information.
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; # End of Perl6::Feeds
|