[Catalyst-commits] r9304 - in
branches/Catalyst-Model-File/moosetastic: . lib/Catalyst/Model
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Sat Feb 14 22:56:57 GMT 2009
Author: t0m
Date: 2009-02-14 22:56:57 +0000 (Sat, 14 Feb 2009)
New Revision: 9304
Modified:
branches/Catalyst-Model-File/moosetastic/Changes
branches/Catalyst-Model-File/moosetastic/Makefile.PL
branches/Catalyst-Model-File/moosetastic/lib/Catalyst/Model/File.pm
Log:
Switch to Moose. This doesn't work with 5.70 as BUILD won't fire..
Modified: branches/Catalyst-Model-File/moosetastic/Changes
===================================================================
--- branches/Catalyst-Model-File/moosetastic/Changes 2009-02-14 22:55:24 UTC (rev 9303)
+++ branches/Catalyst-Model-File/moosetastic/Changes 2009-02-14 22:56:57 UTC (rev 9304)
@@ -1,4 +1,6 @@
+ Switch to use Moose accessors
+
0.08 -
Fix Win32 test failures by forcing stringifies to Unix output format
Modified: branches/Catalyst-Model-File/moosetastic/Makefile.PL
===================================================================
--- branches/Catalyst-Model-File/moosetastic/Makefile.PL 2009-02-14 22:55:24 UTC (rev 9303)
+++ branches/Catalyst-Model-File/moosetastic/Makefile.PL 2009-02-14 22:56:57 UTC (rev 9304)
@@ -5,7 +5,7 @@
perl_version '5.8.1';
requires 'Catalyst' => '5.69';
requires 'Catalyst::Component::InstancePerContext' => 0;
-requires 'Path::Class';
+requires 'MooseX::Types::Path::Class';
build_requires 'Test::More';
Modified: branches/Catalyst-Model-File/moosetastic/lib/Catalyst/Model/File.pm
===================================================================
--- branches/Catalyst-Model-File/moosetastic/lib/Catalyst/Model/File.pm 2009-02-14 22:55:24 UTC (rev 9303)
+++ branches/Catalyst-Model-File/moosetastic/lib/Catalyst/Model/File.pm 2009-02-14 22:56:57 UTC (rev 9304)
@@ -1,17 +1,17 @@
package Catalyst::Model::File;
use Moose;
+use MooseX::Types::Path::Class qw/Dir/;
extends 'Catalyst::Model';
with 'Catalyst::Component::InstancePerContext';
-use NEXT;
use Carp;
use IO::Dir;
use Path::Class ();
use IO::File;
-our $VERSION = 0.07;
+our $VERSION = 0.08;
=head1 NAME
@@ -36,27 +36,16 @@
=head1 METHODS
-=head2 new
-
=cut
-sub new {
- my $self = shift->NEXT::new(@_);
+has dir_create_mask => ( is => 'ro', required => 1, default => 0775 );
+has root_dir => ( is => 'ro', isa => Dir, required => '1', coerce => 1 );
+has directory => ( is => 'rw', isa => Dir, required => '1', coerce => 1, default => sub { Path::Class::dir('/') });
+has _dir => ( is => 'rw', isa => Dir, required => 1, lazy => 1, default => sub { shift->root_dir });
- croak "->config->{root_dir} must be defined for this model"
- unless $self->{root_dir};
-
- unless (ref $self->{root_dir} ) {
- # If a string is provided turn into a Path::Class
- $self->{root_dir} = Path::Class::dir($self->{root_dir})
- }
-
- $self->{dir_create_mask} ||= 0775;
- $self->{root_dir}->mkpath(0, $self->{dir_mask});
- $self->{directory} = Path::Class::dir('/');
- $self->{_dir} = $self->{root_dir};
-
- return $self;
+sub new {
+ my $self = shift;
+ $self->root_dir->mkpath(0, $self->dir_create_mask);
}
sub build_per_context_instance {
@@ -96,7 +85,7 @@
$opt{file} = 1 if $opt{mode} =~ /^both|files$/;
if ($opt{recurse}) {
- $self->{_dir}->recurse(callback => sub {
+ $self->_dir->recurse(callback => sub {
my ($entry) = @_;
push @files, $entry
if !$entry->is_dir && $opt{file}
@@ -118,7 +107,7 @@
sub _rebless {
my ($self, $entity) = @_;
- $entity = $entity->absolute($self->{root_dir});
+ $entity = $entity->absolute($self->root_dir);
if ($entity->is_dir) {
bless $entity, 'Catalyst::Model::File::Dir';
}
@@ -151,27 +140,27 @@
$dir = Path::Class::dir($dir, @_) unless ref $dir;
my @dir_list = ();
- $self->{directory} = Path::Class::dir('');
+ $self->directory(Path::Class::dir(''));
if ($dir->is_absolute) {
- $self->{_dir} = $self->{root_dir};
+ $self->_dir($self->root_dir);
@dir_list = $dir->dir_list(1);
} else {
- $dir = $self->{_dir}->subdir($dir);
- $self->{_dir} = $self->{root_dir};
- return $self unless ($self->{root_dir}->subsumes($dir) );
+ $dir = $self->_dir->subdir($dir);
+ $self->_dir($self->root_dir);
+ return $self unless ($self->root_dir->subsumes($dir) );
- @dir_list = $dir->relative($self->{root_dir})->dir_list;
+ @dir_list = $dir->relative($self->root_dir)->dir_list;
}
# $self->{directory} = $self->{directory}->subdir(@dir_list);
foreach my $subdir (@dir_list) {
- $self->{_dir} = $self->{_dir}->subdir($subdir) unless $subdir eq '..';
- $self->{_dir} = $self->{_dir}->parent if $subdir eq '..';
+ $self->_dir($self->_dir->subdir($subdir)) unless $subdir eq '..';
+ $self->_dir($self->_dir->parent) if $subdir eq '..';
}
- $self->{directory} = $self->{_dir}->relative($self->{root_dir})->absolute('/');
+ $self->directory($self->_dir->relative($self->root_dir)->absolute('/'));
return $self;
}
@@ -187,7 +176,7 @@
sub pwd { shift->directory(@_) }
sub directory {
- return shift->{directory}->as_foreign('Unix');
+ return shift->directory->as_foreign('Unix');
}
=head2 parent
@@ -199,14 +188,14 @@
sub parent {
my ($self) = @_;
- $self->{_dir} = $self->{_dir}->parent;
+ $self->_dir($self->_dir->parent);
- unless ($self->{root_dir}->subsumes($self->{_dir})) {
- $self->{_dir} = $self->{root_dir};
+ unless ($self->root_dir->subsumes($self->_dir)) {
+ $self->_dir($self->root_dir);
return $self;
}
- $self->{directory} = $self->{_dir}->relative($self->{root_dir})->absolute('/');
+ $self->directory($self->_dir->relative($self->root_dir)->absolute('/'));
return $self;
}
@@ -226,10 +215,10 @@
$file = (ref $file ? $file : Path::Class::file($file) )->absolute($self->{_dir});
- return undef unless $self->{root_dir}->subsumes($file);
+ return undef unless $self->root_dir->subsumes($file);
# Make sure the dir tree exists
- $file->dir->mkpath(0, $self->{dir_create_mask});
+ $file->dir->mkpath(0, $self->dir_create_mask);
return $file;
}
More information about the Catalyst-commits
mailing list