| 1 | package Acme::Metification; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use vars qw /$VERSION/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | $VERSION = '1.01'; | |||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use Filter::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # Call the filter routine supplied by Filter::Simple. | ||||||||||
| 13 | # It is time to read the Filter::Simple man page now if you | ||||||||||
| 14 | # haven't done so yet. | ||||||||||
| 15 | |||||||||||
| 16 | # Then pray :) This is ugly. | ||||||||||
| 17 | |||||||||||
| 18 | 3 | FILTER_ONLY | |||||||||
| 19 | all => \&_filter_all, # Used to get the source code lines | ||||||||||
| 20 | code => \&_filter_recurse, # Used to filter recursive replacements | ||||||||||
| 21 | # of limited depth | ||||||||||
| 22 | code => \&_filter_meta;#, # Used to filter replacements | ||||||||||
| 23 | # all => sub {my $co=0;my $c=$_;$c=~s/\n/$co++."\n"/sge;print $c;$_}; | ||||||||||
| 24 | |||||||||||
| 25 | 3 | my @src_lines; | |||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | sub _filter_all { | ||||||||
|
Subroutine
_filter_all: called CC=2 SCAR=7.6
| |||||||||||
| 28 | 2 | ▶ | if (@src_lines) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | die "Filter invoked multiple times. Not supported in this version!"; | |||||||||
| 30 | } | ||||||||||
| 31 | 2 | @src_lines = split /\n/; | |||||||||
| 32 | |||||||||||
| 33 | 2 | $_; | |||||||||
| 34 | }; | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 2 | ▶ | sub _filter_meta { | ||||||||
|
Subroutine
_filter_meta: called CC=2 SCAR=6.9
| |||||||||||
| 38 | 2 | ▶ | while ( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | s{^\s*meta\s*(.*)}{ | ||||||||||
| 40 | 1 | _replace_meta($1) | |||||||||
| 41 | }mge | ||||||||||
| 42 | ) {} | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | sub _filter_recurse { | ||||||||
|
Subroutine
_filter_recurse: called CC=3 SCAR=11.0
| |||||||||||
| 46 | |||||||||||
| 47 | 2 | ▶ | while ( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | s{^\s*recursemeta\s*depth\s*\=\>\s*(\d+)\s*,\s*(.+)}! | ||||||||||
| 49 | 10 | my $depth = $1-1; | |||||||||
| 50 | 10 | my $rep = _replace_meta($2); | |||||||||
| 51 | 10 | ▶ | if ($depth > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 9 | $rep =~ s{^\s*recursemeta\s*depth\s*\=\>\s*(\d+)\s*,\s*(.+)}| | |||||||||
| 53 | 9 | "recursemeta depth => " . ($depth) . ", $2" | |||||||||
| 54 | |mge; | ||||||||||
| 55 | 1 | } else { $rep =~ s{^\s*recursemeta\s*depth\s*\=\>\s*(\d+)\s*,\s*(.+)}||mg } | |||||||||
| 56 | 10 | $rep; | |||||||||
| 57 | !mge | ||||||||||
| 58 | ) {} | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 11 | ▶ | sub _replace_meta { | ||||||||
|
Subroutine
_replace_meta: called CC=9 SCAR=23.7
| |||||||||||
| 62 | 11 | my $match = shift; | |||||||||
| 63 | 11 | ▶ | $match =~ /(\d+)\s*,\s*(\d+)/ or $match =~ /(\d+)/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 11 | my ($start, $end) = ($1, $2); | |||||||||
| 66 | |||||||||||
| 67 | 11 | ▶ | return '' if not defined $start; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | 11 | $start = int $start; | |||||||||
| 70 | 11 | ▶ | $start = @src_lines + $start if $start < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 11 | ▶ | $start = $#src_lines if $start > $#src_lines; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 11 | ▶ | return $src_lines[$start] if not defined $end; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | 11 | $end = int $end; | |||||||||
| 76 | 11 | ▶ | $end = @src_lines + $end if $end < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 11 | ▶ | $end = $#src_lines if $end > $#src_lines; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | |||||||||||
| 79 | 11 | ▶ | ($start, $end) = ($end, $start) if $start > $end; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 11 | return join "\n", (@src_lines[($start .. $end)]); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 3 | 1; | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||