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.02";
3              
4 20     20   1488432 use 5.014;
  20         216  
5 20     20   83 use warnings;
  20         39  
  20         510  
6              
7 20     20   1123 use open IO => 'utf8', ':std';
  20         1210  
  20         82  
8 20     20   12757 use Encode;
  20         164781  
  20         1178  
9 20     20   9391 use Pod::Usage;
  20         690034  
  20         2163  
10 20     20   798 use Data::Dumper;
  20         5802  
  20         926  
11 20     20   8490 use Text::ANSI::Tabs qw(ansi_expand ansi_unexpand);
  20         1042163  
  20         1667  
12              
13             our $DEFAULT_UNEXPAND;
14              
15 20     20   8784 use Getopt::EX::Hashed 1.05; {
  20         117600  
  20         115  
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 20     20   8972 } no Getopt::EX::Hashed;
  20         54  
  20         70  
62              
63             sub run {
64 16     16 0 12775815 my $app = shift;
65 16 50       200 local @ARGV = map { utf8::is_utf8($_) ? $_ : decode('utf8', $_) } @_;
  31         2422  
66              
67 20     20   9377 use Getopt::EX::Long qw(:DEFAULT ExConfigure Configure);
  20         612731  
  20         4968  
68 16         1865 ExConfigure BASECLASS => [ __PACKAGE__, 'Getopt::EX' ];
69 16         1573 Configure qw(bundling pass_through);
70 16 100       2127 $app->getopt || pod2usage();
71 10         8360 @ARGV = @{$app->ARGV};
  10         140  
72              
73 10 100       234 my $action = $app->unexpand ? \&ansi_unexpand : \&ansi_expand;
74              
75 10         1396 while (<>) {
76 12         20265 print $action->($_);
77             }
78              
79 10         51758 return 0;
80             }
81              
82             1;
83             __END__