line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sweet::Dir; |
2
|
3
|
|
|
3
|
|
28379
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Try::Tiny; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use MooseX::Types::Path::Class; |
7
|
|
|
|
|
|
|
use File::Path qw(make_path remove_tree); |
8
|
|
|
|
|
|
|
use Try::Tiny; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Sweet::File; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'path' => ( |
13
|
|
|
|
|
|
|
builder => '_build_path', |
14
|
|
|
|
|
|
|
coerce => 1, |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => 'Path::Class::Dir', |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub create { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
my $path = $self->path; |
23
|
|
|
|
|
|
|
my $make_path_error; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return $self if $self->is_a_directory; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
try { |
28
|
|
|
|
|
|
|
make_path( $path, { error => \$make_path_error } ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
catch { |
31
|
|
|
|
|
|
|
die $make_path_error; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub does_not_exists { |
36
|
|
|
|
|
|
|
return !-d shift->path; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub erase { |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $path = $self->path; |
43
|
|
|
|
|
|
|
my $remove_path_error; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
try { |
46
|
|
|
|
|
|
|
remove_path( $path, { error => \$remove_path_error } ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
catch { |
49
|
|
|
|
|
|
|
die $remove_path_error; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub file { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $name = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $file = Sweet::File->new( dir => $self, name => $name ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $file; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub is_a_directory { -d shift->path } |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub sub_dir { |
66
|
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my @path = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $sub_dir_path = File::Spec->catfile( $self->path, @path ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $sub_dir = Sweet::Dir->new( path => $sub_dir_path ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return $sub_dir; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use overload q("") => sub { shift->path }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding utf8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Sweet::Dir |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
use Sweet::Dir; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $dir = Sweet::Dir->new(path => '/path/to/dir'); |
96
|
|
|
|
|
|
|
$dir->create; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 path |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 create |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 does_not_exists |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 erase |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 is_a_directory |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 sub_dir |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|