File Coverage

blib/lib/Acme/Echo.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Acme::Echo;
2              
3 5     5   140260 use warnings;
  5         13  
  5         398  
4 5     5   31 use strict;
  5         10  
  5         352  
5              
6             our $VERSION = '0.02';
7              
8 5     5   5261 use Filter::Simple;
  5         124390  
  5         36  
9 5     5   5528 use PPI;
  5         852295  
  5         2865  
10             our %modes;
11             our $line_fmt = "%s\n";
12             our $src_fmt = "==>\n%s\n<==\n";
13             our $fh = *STDOUT;
14             sub import {
15             my $pkg = shift;
16             while ( $_ = shift @_ ){
17             if( /^before|after|lines$/ ){
18             $modes{ lc $_ } = undef;
19             }elsif( $_ eq 'line_fmt' ){
20             $line_fmt = shift;
21             }elsif( $_ eq 'src_fmt' ){
22             $src_fmt = shift;
23             }elsif( $_ eq 'fh' ){
24             $fh = shift;
25             }else{
26             die "bad parameter '$_' to Acme::Echo";
27             }
28             }
29             }
30             FILTER {
31             my $src = $_;
32             my $print = 'print $Acme::Echo::fh';
33             $_ = exists $modes{lines}
34             ?
35             do {
36             my $s = "";
37             my $d = PPI::Document->new(\$src);
38             foreach my $node ( @{ $d->find('PPI::Statement') } ){
39             next unless $node->parent == $d;
40             if( $node->class eq 'PPI::Statement::Compound' ){
41             $s .= "$print q{COMPOUND STATEMENTS NOT SUPPORTED IN lines MODE\n};\n" . $node->content;
42             }elsif( $node->class eq 'PPI::Statement::Sub' ){
43             $s .= "$print q{SUB STATEMENTS NOT SUPPORTED IN lines MODE\n};\n" . $node->content;
44             }else{
45             $s .= sprintf "$print q{$line_fmt}; %s\n", $node->content, $node->content;
46             }
47             }
48             $s;
49             }
50             : $src ;
51             my $block = sprintf "\n;$print q{$src_fmt};\n", $src;
52             $_ = $block . $_ if exists $modes{before};
53             $_ = $_ . $block if exists $modes{after};
54             };
55             1;
56             __END__