Catalyst-Model-File
view release on metacpan or search on metacpan
lib/Catalyst/Model/File.pm view on Meta::CPAN
my @lines = $self->slurp($file, chomp => 1);
=cut
sub slurp {
my $file = shift->file(shift) or return wantarray ? () : undef;
return $file->stat ? $file->slurp(@_) : wantarray ? () : undef;
}
=head2 $self->splat($file, PRINT_ARGS)
Does a print to C<$file> with the specified C<PRINT_ARGS>. Does the same as
C<$self->file->openw->print(@_)>
=cut
sub splat {
my $file = shift->file(shift) or return;
$file->openw->print(@_);
}
__PACKAGE__->meta->make_immutable;
package #
Catalyst::Model::File::File;
use base 'Path::Class::File';
sub stringify {
return $_[0]->{stringify_as} || $_[0]->abs_stringify;
}
sub abs_stringify {
Path::Class::File::stringify(shift)
}
# All these would probably be better done with Moose or something, but i'm lazy
sub open {
my $s = shift;
local $s->{stringify_as};
return $s->SUPER::open(@_);
}
sub touch {
my $s = shift;
local $s->{stringify_as};
return $s->SUPER::touch(@_);
}
sub remove {
my $s = shift;
local $s->{stringify_as};
return $s->SUPER::touch(@_);
}
sub stat {
my $s = shift;
local $s->{stringify_as};
return $s->SUPER::stat(@_);
}
sub lstat {
my $s = shift;
local $s->{stringify_as};
return $s->SUPER::lstat(@_);
}
@Catalyst::Model::File::Dir::ISA = 'Path::Class::Dir';
sub Catalyst::Model::File::Dir::stringify {
return $_[0]->{stringify_as}
|| Path::Class::Dir::stringify($_[0]);
}
=head1 AUTHOR
Ash Berlin, C<ash@cpan.org>
=head1 LICENSE
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
1;
( run in 0.651 second using v1.01-cache-2.11-cpan-39bf76dae61 )