| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*-CPerl-*- |
|
2
|
|
|
|
|
|
|
# Last changed Time-stamp: <2019-08-23 20:19:04 mtw> |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
FileDirUtil - A Moose Role for basic File IO |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package FooBar; |
|
11
|
|
|
|
|
|
|
use Moose; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'FileDirUtil'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub BUILD { |
|
16
|
|
|
|
|
|
|
my $self = shift; |
|
17
|
|
|
|
|
|
|
$self->set_ifilebn; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
FileDirUtil is a convenience Moose Role for basic File IO, providing |
|
23
|
|
|
|
|
|
|
transparent access to L<Path::Class::File> and L<Path::Class::Dir> for |
|
24
|
|
|
|
|
|
|
input files and output directories, respectively, via the following |
|
25
|
|
|
|
|
|
|
attributes: |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 3 |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item ifile |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
A string representing the path to an input file in platform-native |
|
32
|
|
|
|
|
|
|
syntax, e.g. I<'moo/foo.bar'>. This will be coerced into a |
|
33
|
|
|
|
|
|
|
L<Path::Class::File> object. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item odir |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
A L<Path::Class::Dir> object or an ArrayRef specifying path segments |
|
38
|
|
|
|
|
|
|
of directories which will be joined to create a single |
|
39
|
|
|
|
|
|
|
L<Path::Class::Dir> directory object. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=back |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
package FileDirUtil; |
|
46
|
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
120729
|
use version; our $VERSION = qv('0.04'); |
|
|
1
|
|
|
|
|
1957
|
|
|
|
1
|
|
|
|
|
6
|
|
|
48
|
1
|
|
|
1
|
|
791
|
use Moose::Util::TypeConstraints; |
|
|
1
|
|
|
|
|
292001
|
|
|
|
1
|
|
|
|
|
11
|
|
|
49
|
1
|
|
|
1
|
|
2573
|
use Moose::Role; |
|
|
1
|
|
|
|
|
181786
|
|
|
|
1
|
|
|
|
|
4
|
|
|
50
|
1
|
|
|
1
|
|
5695
|
use Path::Class::File; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
51
|
1
|
|
|
1
|
|
5
|
use Path::Class::Dir; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
52
|
1
|
|
|
1
|
|
14
|
use File::Basename; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
78
|
|
|
53
|
1
|
|
|
1
|
|
780
|
use Params::Coerce (); |
|
|
1
|
|
|
|
|
1601
|
|
|
|
1
|
|
|
|
|
24
|
|
|
54
|
1
|
|
|
1
|
|
516
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
8204
|
|
|
|
1
|
|
|
|
|
4
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
subtype 'MyFile' => as class_type('Path::Class::File'); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
coerce 'MyFile' |
|
59
|
|
|
|
|
|
|
=> from 'Str' |
|
60
|
|
|
|
|
|
|
=> via { Path::Class::File->new($_) }; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
subtype 'MyDir' => as class_type('Path::Class::Dir'); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
coerce 'MyDir' |
|
65
|
|
|
|
|
|
|
=> from 'Object' |
|
66
|
|
|
|
|
|
|
=> via {$_ -> isa('Path::Class::Dir') ? $_ : Params::Coerce::coerce ('Path::Class::Dir', $_); } |
|
67
|
|
|
|
|
|
|
=> from 'ArrayRef' |
|
68
|
|
|
|
|
|
|
=> via { Path::Class::Dir->new( @{ $_ } ) }; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has 'ifile' => ( |
|
71
|
|
|
|
|
|
|
is => 'ro', |
|
72
|
|
|
|
|
|
|
isa => 'MyFile', |
|
73
|
|
|
|
|
|
|
predicate => 'has_ifile', |
|
74
|
|
|
|
|
|
|
coerce => 1, |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has 'ifilebn' => ( |
|
78
|
|
|
|
|
|
|
is => 'rw', |
|
79
|
|
|
|
|
|
|
isa => 'Str', |
|
80
|
|
|
|
|
|
|
predicate => 'has_ifilebn', |
|
81
|
|
|
|
|
|
|
init_arg => undef, # make this unsettable via constructor |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
has 'odir' => ( |
|
85
|
|
|
|
|
|
|
is => 'rw', |
|
86
|
|
|
|
|
|
|
isa => 'MyDir', |
|
87
|
|
|
|
|
|
|
predicate => 'has_odir', |
|
88
|
|
|
|
|
|
|
coerce => 1, |
|
89
|
|
|
|
|
|
|
); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# This should be set automatically inside a BUILD methods, however it |
|
92
|
|
|
|
|
|
|
# semms this doesnt work well for Roles. Hence do it the ugly way and |
|
93
|
|
|
|
|
|
|
# call this method manually inside your object... |
|
94
|
|
|
|
|
|
|
sub set_ifilebn { |
|
95
|
2
|
|
|
2
|
0
|
2575
|
my $self = shift; |
|
96
|
2
|
|
|
|
|
65
|
$self->ifilebn(fileparse($self->ifile->basename, qr/\.[^.]*/)); |
|
97
|
|
|
|
|
|
|
}; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# for perl tests below |
|
100
|
|
|
|
|
|
|
package FDU; |
|
101
|
1
|
|
|
1
|
|
330
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
102
|
|
|
|
|
|
|
with 'FileDirUtil'; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item L<Path::Class::Dir> |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item L<Path::Class::File> |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Michael T. Wolfinger, C<< <michael at wolfinger.eu> >> |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 BUGS |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
126
|
|
|
|
|
|
|
C<bug-filedirutil at rt.cpan.org>, or through the web |
|
127
|
|
|
|
|
|
|
interface at |
|
128
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FileDirUtil>. |
|
129
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
|
130
|
|
|
|
|
|
|
progress on your bug as I make changes. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SUPPORT |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
perldoc FileDirUtil |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You can also look for information at: |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 1 |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * metaCPAN |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L<https://metacpan.org/pod/FileDirUtil> |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Copyright 2017-2019 Michael T. Wolfinger <michael@wolfinger.eu> and <michael.wolfinger@univie.ac.at> |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
155
|
|
|
|
|
|
|
it under the terms of the GNU Affero General Public License as |
|
156
|
|
|
|
|
|
|
published by the Free Software Foundation; either version 3 of the |
|
157
|
|
|
|
|
|
|
License, or (at your option) any later version. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but |
|
160
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
161
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
162
|
|
|
|
|
|
|
Affero General Public License for more details. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public |
|
165
|
|
|
|
|
|
|
License along with this program. If not, see |
|
166
|
|
|
|
|
|
|
L<http://www.gnu.org/licenses/>. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |