/[Frey]/trunk/lib/Frey/File.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/File.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1133 - (show annotations)
Tue Jun 30 15:10:55 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 909 byte(s)
make classes immutable and remove moose droppings to make Perl::Critic::Moose happy
1 package Frey::File;
2 use Moose::Role;
3
4 use File::Slurp qw//;
5 use Carp qw/confess/;
6
7 =head2 read_file
8
9 L<File::Slurp/read_file>
10
11 =cut
12
13 sub read_file { shift ; File::Slurp::read_file( @_ ) }
14
15 =head2 write_file
16
17 L<File::Slurp/write_file>
18
19 =cut
20
21 sub write_file { shift ; File::Slurp::write_file( @_ ) }
22
23 =head2 dir_extension
24
25 Returns array of full paths with some extension
26
27 my @files = $self->dir_extension( 'var/directory/', qw/\.(ya?ml)$/ );
28
29 =cut
30
31 sub dir_extension {
32 my ($self,$path,$extension_regex) = @_;
33
34 confess "extension not regex" unless ref($extension_regex) eq 'Regexp';
35
36 opendir(my $dir, $path) || die "can't opendir $path: $!";
37 my @files = map { "$path/$_" } sort grep { $extension_regex && -f "$path/$_" } readdir($dir);
38 closedir $dir;
39 return @files;
40 }
41
42 sub strip_path_extension {
43 my ( $self, $path ) = @_;
44 $path =~ s{^(?:.*/)?([^/]+)\.[^/]+$}{$1};
45 return $path;
46 }
47
48 no Moose::Role;
49
50 1;

  ViewVC Help
Powered by ViewVC 1.1.26