/[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 719 by dpavlin, Thu Dec 4 18:39:37 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  sub read_file { shift ; File::Slurp->read_file( @_ ) }  =head2 read_file
8  sub write_file { shift ; File::Slurp->write_file( @_ ) }  
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  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26