/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26