File Coverage

blib/lib/App/ansiexpand.pm
Criterion Covered Total %
statement 41 41 100.0
branch 5 6 83.3
condition n/a
subroutine 11 11 100.0
pod 0 1 0.0
total 57 59 96.6


line stmt bran cond sub pod time code
1             package App::ansiexpand;
2             our $VERSION = "1.03";
3              
4 21     21   1873725 use 5.014;
  21         283  
5 21     21   110 use warnings;
  21         42  
  21         628  
6              
7 21     21   868 use open IO => 'utf8', ':std';
  21         1255  
  21         126  
8 21     21   13812 use Encode;
  21         201035  
  21         1441  
9 21     21   11593 use Pod::Usage;
  21         890337  
  21         2671  
10 21     21   925 use Data::Dumper;
  21         6571  
  21         1126  
11 21     21   10069 use Text::ANSI::Tabs qw(ansi_expand ansi_unexpand);
  21         1288556  
  21         2125  
12              
13             our $DEFAULT_UNEXPAND;
14              
15 21     21   10526 use Getopt::EX::Hashed 1.05; {
  21         145602  
  21         140  
16              
17             Getopt::EX::Hashed->configure(DEFAULT => [ is => 'ro' ]);
18              
19             has unexpand => ' u ! ' , default => $DEFAULT_UNEXPAND;
20             has ambiguous => ' =s ' , any => [ qw(wide narrow) ];
21             has tabstop => ' t =i ' , min => 1;
22             has tabhead => ' =s ' ;
23             has tabspace => ' =s ' ;
24             has tabstyle => ' ts =s ' ;
25             has help => ' h ' ;
26             has version => ' v ' ;
27              
28             has '+tabstop' => sub {
29             $_->{$_[0]} = $Text::ANSI::Tabs::tabstop = $_[1];
30             };
31              
32             has [ qw(+tabhead +tabspace +tabstyle) ] => sub {
33             Text::ANSI::Tabs->configure("$_[0]" => $_[1]);
34             };
35              
36             has '+help' => sub {
37             pod2usage
38             -verbose => 99,
39             -sections => [ qw(SYNOPSIS VERSION) ];
40             };
41              
42             has '+version' => sub {
43             print "Version: $VERSION\n";
44             exit;
45             };
46              
47             has ARGV => default => [];
48             has '<>' => sub {
49             if ($_[0] =~ /^-([0-9]+)$/x) {
50             $_->{tabstop} = $Text::ANSI::Tabs::tabstop = $1 or
51             die "$_[0]: invalid tabstop\n";
52             } else {
53             if ($_[0] =~ /^-{1,2}+(.+)/) {
54             warn "Unknown option: $1\n";
55             pod2usage();
56             }
57             push @{$_->ARGV}, $_[0];
58             }
59             };
60              
61 21     21   11028 } no Getopt::EX::Hashed;
  21         54  
  21         126  
62              
63             sub run {
64 17     17 0 15411507 my $app = shift;
65 17 50       225 local @ARGV = map { utf8::is_utf8($_) ? $_ : decode('utf8', $_) } @_;
  32         2760  
66              
67 21     21   11428 use Getopt::EX::Long qw(:DEFAULT ExConfigure Configure);
  21         823511  
  21         8286  
68 17         2384 ExConfigure BASECLASS => [ __PACKAGE__, 'Getopt::EX' ];
69 17         1776 Configure qw(bundling pass_through);
70 17 100       2672 $app->getopt || pod2usage();
71 11         10095 @ARGV = @{$app->ARGV};
  11         199  
72              
73 11 100       185 my $action = $app->unexpand ? \&ansi_unexpand : \&ansi_expand;
74              
75 11         1456 while (<>) {
76 13         23923 print $action->($_);
77             }
78              
79 11         97882 return 0;
80             }
81              
82             1;
83             __END__