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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 818 by dpavlin, Fri Dec 12 18:00:21 2008 UTC revision 972 by dpavlin, Fri Jan 9 19:33:26 2009 UTC
# Line 2  package Frey::File; Line 2  package Frey::File;
2  use Moose::Role;  use Moose::Role;
3    
4  use File::Slurp qw//;  use File::Slurp qw//;
5    use Carp qw/confess/;
6    
7  =head2 read_file  =head2 read_file
8    
# Line 21  sub write_file { shift ; File::Slurp::wr Line 22  sub write_file { shift ; File::Slurp::wr
22    
23  =head2 dir_extension  =head2 dir_extension
24    
25    my @files = $self->dir_extension( 'var/directory/', '\.(ya?ml)$' );  Returns array of full paths with some extension
26    
27      my @files = $self->dir_extension( 'var/directory/', qw/\.(ya?ml)$/ );
28    
29  =cut  =cut
30    
31  sub dir_extension {  sub dir_extension {
32          my ($self,$path,$extension) = @_;          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: $!";          opendir(my $dir, $path) || die "can't opendir $path: $!";
37          my @files = sort grep { m/$extension/ } readdir($dir);          my @files = map { "$path/$_" } sort grep { $extension_regex && -f "$path/$_" } readdir($dir);
38          closedir $dir;          closedir $dir;
39          return @files;          return @files;
40  }  }
41    
42    sub strip_path_extension {
43            my ( $self, $path ) = @_;
44            $path =~ s{^(?:.*/)?([^/]+)\.[^/]+$}{$1};
45            return $path;
46    }
47    
48  1;  1;

Legend:
Removed from v.818  
changed lines
  Added in v.972

  ViewVC Help
Powered by ViewVC 1.1.26