File Coverage

lib/Path/Extended/Class/Dir.pm
Criterion Covered Total %
statement 33 44 75.0
branch 14 16 87.5
condition 3 6 50.0
subroutine 9 13 69.2
pod 9 9 100.0
total 68 88 77.2


line stmt bran cond sub pod time code
1             package Path::Extended::Class::Dir;
2              
3 3     3   16 use strict;
  3         27  
  3         145  
4 3     3   18 use warnings;
  3         5  
  3         117  
5 3     3   15 use base qw( Path::Extended::Dir );
  3         5  
  3         1860  
6              
7             sub _initialize {
8 102     102   146 my ($self, @args) = @_;
9              
10 102 100 100     389 return if @args && !defined $args[0];
11              
12 101 100       498 my $dir = @args ? File::Spec->catdir( @args ) : File::Spec->curdir;
13              
14 101         239 $self->_set_path($dir);
15 101         164 $self->{is_dir} = 1;
16 101         118 $self->{_compat} = 1;
17              
18 101         265 $self;
19             }
20              
21             sub new_foreign {
22 0     0 1 0 my ($class, $type, @args) = @_;
23 0         0 $class->new(@args);
24             }
25              
26             sub absolute {
27 2     2 1 4 my $self = shift;
28 2         5 $self->{_base} = undef;
29 2         11 $self;
30             }
31              
32             sub relative {
33 0     0 1 0 my $self = shift;
34 0 0       0 my $base = @_ % 2 ? shift : undef;
35 0         0 my %options = @_;
36 0   0     0 $self->{_base} = $base || $options{base} || File::Spec->curdir;
37 0         0 $self;
38             }
39              
40 0     0 1 0 sub cleanup { shift } # is always clean
41 15     15 1 58 sub as_foreign { shift } # does nothing
42              
43             sub dir_list {
44 11     11 1 2248 my $self = shift;
45              
46 11         48 my @parts = $self->_parts;
47 11 100       30 return @parts unless @_;
48              
49 9         10 my $offset = shift;
50 9 100       17 $offset = @parts + $offset if $offset < 0;
51              
52 9 100       32 return wantarray ? @parts[$offset .. $#parts] : $parts[$offset] unless @_;
    100          
53              
54 5         7 my $length = shift;
55 5 100       9 $length = @parts + $length - $offset if $length < 0;
56 5         22 return @parts[$offset .. $length + $offset - 1];
57             }
58              
59             sub tempfile {
60 0     0 1 0 my $self = shift;
61 0         0 require File::Temp;
62 0         0 return File::Temp::tempfile(@_, DIR => $self->stringify);
63             }
64              
65 8     8 1 45 sub mkdir {require File::Path; File::Path::mkpath(shift->path, @_)}
  8         19  
66 7     7 1 3283 sub rmdir {require File::Path; File::Path::rmtree(shift->path, @_)}
  7         21  
67             *mkpath = \&mkdir;
68             *rmtree = *remove = \&rmdir;
69              
70             1;
71              
72             __END__