File Coverage

blib/lib/App/FilterUtils/ascii.pm
Criterion Covered Total %
statement 27 47 57.4
branch 0 6 0.0
condition n/a
subroutine 9 13 69.2
pod 3 3 100.0
total 39 69 56.5


line stmt bran cond sub pod time code
1 1     1   902 use strict;
  1         2  
  1         24  
2 1     1   5 use warnings;
  1         1  
  1         39  
3             package App::FilterUtils::ascii;
4             # ABSTRACT: Echo only ASCII characters
5             our $VERSION = '0.001'; # VERSION
6 1     1   5 use base 'App::Cmd::Simple';
  1         1  
  1         72  
7 1     1   15 use utf8;
  1         2  
  1         5  
8 1     1   21 use charnames qw();
  1         1  
  1         17  
9 1     1   4 use open qw( :encoding(UTF-8) :std );
  1         1  
  1         5  
10 1     1   204 use Module::Load qw(load);
  1         1  
  1         8  
11 1     1   69 use Getopt::Long::Descriptive;
  1         3  
  1         8  
12              
13 1     1   258 use utf8;
  1         2  
  1         3  
14              
15             =pod
16              
17             =encoding utf8
18              
19             =head1 NAME
20              
21             ascii - Echo only ASCII characters
22              
23             =head1 SYNOPSIS
24              
25             $ ascii cafĂ©
26             caf
27              
28             =head1 OPTIONS
29              
30             =head2 version / v
31              
32             Shows the current version number
33              
34             $ ascii --version
35              
36             =head2 help / h
37              
38             Shows a brief help message
39              
40             $ ascii --help
41              
42             =cut
43              
44             sub opt_spec {
45             return (
46 0     0 1   [ 'version|v' => "show version number" ],
47             [ 'help|h' => "display a usage message" ],
48             );
49             }
50              
51             sub validate_args {
52 0     0 1   my ($self, $opt, $args) = @_;
53              
54 0 0         if ($opt->{'help'}) {
    0          
55 0           my ($opt, $usage) = describe_options(
56             $self->usage_desc(),
57             $self->opt_spec(),
58             );
59 0           print $usage;
60 0           print "\n";
61 0           print "For more detailed help see 'perldoc App::FilterUtils::ascii'\n";
62              
63 0           print "\n";
64 0           exit;
65             }
66             elsif ($opt->{'version'}) {
67 0           print $App::FilterUtils::ascii::VERSION, "\n";
68 0           exit;
69             }
70              
71 0           return;
72             }
73              
74             sub execute {
75 0     0 1   my ($self, $opt, $args) = @_;
76              
77 0 0   0     my $readarg = @$args ? sub { shift @$args } : sub { };
  0            
  0            
78 0           while (defined($_ = $readarg->())) {
79 0           chomp;
80 0           print s/[^[:ascii:]]//gr;
81             }
82              
83 0           return;
84             }
85              
86             1;
87              
88             __END__