File Coverage

blib/lib/App/supertouch.pm
Criterion Covered Total %
statement 32 45 71.1
branch 12 26 46.1
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 50 80 62.5


line stmt bran cond sub pod time code
1             package App::supertouch;
2              
3 1     1   243052 use strict;
  1         8  
  1         29  
4 1     1   5 use warnings;
  1         2  
  1         22  
5 1     1   28 use 5.008001;
  1         3  
6 1     1   872 use Path::Tiny qw( path );
  1         11708  
  1         401  
7              
8             # ABSTRACT: Touch with directories
9             our $VERSION = '0.02'; # VERSION
10              
11              
12             sub main
13             {
14 3     3 0 12947 my(undef, @args) = @_;
15              
16 3         6 my $verbose = 0;
17 3         6 my $options = 1;
18              
19 3         8 foreach my $arg (@args)
20             {
21 3 50 33     19 if($options && $arg =~ /^-/)
22             {
23 0 0       0 if($arg eq '--')
    0          
24             {
25 0         0 $options = 0;
26             }
27             elsif($arg eq '-v')
28             {
29 0         0 $verbose = 1;
30             }
31 0         0 next;
32             }
33 3 50       10 if($arg eq '')
34             {
35 0         0 print STDERR "'' (empty) is not a legal filename";
36 0         0 return 2;
37             }
38 3 100       16 if($arg =~ s{[\\/]$}{})
39             {
40 1         9 my $dir = path($arg);
41 1 50       31 if($dir->is_file)
42             {
43 0         0 print STDERR "$dir is a file";
44 0         0 return 2;
45             }
46 1 50       34 unless(-d $dir)
47             {
48 1 50       17 print "DIR @{[ $dir ]}\n" if $verbose;
  0         0  
49 1         18 $dir->mkpath;
50             }
51             }
52             else
53             {
54 2         8 my $file = path($arg);
55 2 50       61 if($file->is_dir)
56             {
57 0         0 print STDERR "$file is a directory";
58 0         0 return 2;
59             }
60 2 50       64 unless(-d $file->parent)
61             {
62 2 50       217 print "DIR @{[ $file->parent ]}\n" if $verbose;
  0         0  
63 2         10 $file->parent->mkpath;
64             }
65 2 50       660 unless(-f $file)
66             {
67 2 50       54 print "FILE @{[ $file ]}\n" if $verbose;
  0         0  
68 2         13 $file->touch;
69             }
70             }
71             }
72              
73 3         836 return 0;
74             }
75              
76             1;
77              
78             __END__