File Coverage

blib/lib/File/Rename/Options.pm
Criterion Covered Total %
statement 29 33 87.8
branch 10 16 62.5
condition 3 6 50.0
subroutine 7 7 100.0
pod 2 2 100.0
total 51 64 79.6


line stmt bran cond sub pod time code
1             package File::Rename::Options;
2 21     21   132317 use 5.032; # use strict; use warnings;
  21         78  
3            
4 21     21   16223 use Getopt::Long 2.24 ();
  21         298046  
  21         12261  
5            
6             our $VERSION = 2.01;
7             our $IMPORTED;
8            
9             sub import {
10 21     21   63 my $pack = shift;
11 21 50       104 if( $IMPORTED++ ) {
12 0         0 require Carp;
13 0         0 Carp::cluck("$pack->import() called twice");
14             }
15 21         57 my @config = qw(
16             posix_default
17             no_ignore_case
18             );
19 21         57 push @config, @_;
20 21         85 Getopt::Long::Configure(@config);
21             }
22            
23             sub GetOptions {
24 31     31 1 484669 my ($no_code) = @_;
25 31         94 my @expression;
26 31         77 my $fullpath = 1;
27             Getopt::Long::GetOptions(
28             '-v|verbose' => \my $verbose,
29             '-0|null' => \my $null,
30             '-n|nono' => \my $nono,
31             '-f|force' => \my $force,
32             '-h|?|help' => \my $help,
33             '-m|man' => \my $man,
34             '-V|version' => \my $version,
35 4     4   5184 '-d|filename' => sub { undef $fullpath },
36             '-path|fullpath!' => \$fullpath,
37             '-e=s' => \@expression,
38             '-E=s' =>
39             sub {
40 8     8   6204 my(undef, $e) = @_;
41 8         18 $e .= ';';
42 8         79 push @expression, $e;
43             },
44 31 50       777 '-u|unicode:s' => \my $unicode,
45             ) or return;
46            
47 31         36424 my $options = {
48             verbose => $verbose,
49             input_null => $null,
50             no_action => $nono,
51             over_write => $force,
52             filename_only => !$fullpath,
53             show_help => $help,
54             show_manual => $man,
55             show_version => $version,
56             unicode_strings => defined $unicode,
57             encoding => $unicode,
58             };
59 31 100       139 return $options if $no_code;
60 25 100 33     229 return $options if $help or $man or $version;
      66        
61            
62 23 100       81 if( @expression ) {
63 9         49 $options->{_code} = join "\n", @expression;
64             }
65             else {
66 14 50       49 return unless @ARGV;
67 14         52 $options->{_code} = shift @ARGV;
68             }
69 23         132 return $options;
70             }
71            
72             sub bad_encoding {
73 23     23 1 46 my $options = shift;
74 23         55 my $encoding = $options->{encoding};
75 23 50       98 return unless $encoding;
76 0 0         return unless $encoding =~ /[^\s\w.-]/;
77 0           return 1
78             }
79            
80             1;
81             __END__