[Bps-public-commit] r16970 - in Prophet/trunk: . lib/Prophet lib/Prophet/CLI lib/Prophet/CLI/Command lib/Prophet/Replica
jesse at bestpractical.com
jesse at bestpractical.com
Fri Nov 21 19:17:33 EST 2008
Author: jesse
Date: Fri Nov 21 19:17:33 2008
New Revision: 16970
Modified:
Prophet/trunk/Makefile.PL
Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm
Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm
Prophet/trunk/lib/Prophet/Config.pm
Prophet/trunk/lib/Prophet/DatabaseSetting.pm
Prophet/trunk/lib/Prophet/Record.pm
Prophet/trunk/lib/Prophet/Replica/prophet.pm
Prophet/trunk/lib/Prophet/Test.pm
Prophet/trunk/t/export.t
Prophet/trunk/t/publish-html.t
Prophet/trunk/t/publish-pull.t
Log:
* Remove dependency on Path::Class
Modified: Prophet/trunk/Makefile.PL
==============================================================================
--- Prophet/trunk/Makefile.PL (original)
+++ Prophet/trunk/Makefile.PL Fri Nov 21 19:17:33 2008
@@ -8,7 +8,6 @@
requires('Params::Validate');
requires('IPC::Run3');
requires('Data::UUID');
-requires('Path::Class');
requires('Digest::SHA1'); # Core in 5.10
requires('LWP::Simple'); # Part of lib-www-perl
requires('URI');
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm Fri Nov 21 19:17:33 2008
@@ -4,7 +4,8 @@
with 'Prophet::CLI::PublishCommand';
with 'Prophet::CLI::CollectionCommand';
-use Path::Class;
+use File::Path;
+use File::Spec;
sub view_classes {
return ['Prophet::Server::View'];
@@ -53,14 +54,14 @@
sub export_html {
my $self = shift;
- my $path = dir($self->arg('path'));
+ my $path = $self->arg('path');
# if they specify both html and replica, then stick rendered templates
# into a subdirectory. if they specify only html, assume they really
# want to publish directly into the specified directory
if ($self->has_arg('replica')){
- $path = $path->subdir('html');
- $path->mkpath;
+ $path = File::Spec->catdir($path => 'html');
+ mkpath([$path]);
}
$self->render_templates_into($path);
@@ -78,18 +79,18 @@
my @types = $self->type || $self->types_to_render;
for my $type (@types) {
- my $subdir = $dir->subdir($type);
- $subdir->mkpath;
+ my $subdir = File::Spec->catdir($dir, $type);
+ mkpath([$subdir]);
my $records = $self->get_collection_object(type => $type);
$records->matching(sub { 1 });
- my $fh = $subdir->file('index.html')->openw;
+ open (my $fh, '>',File::Spec->catdir($subdir => 'index.html'));
print { $fh } Template::Declare->show('record_table' => $records);
close $fh;
for my $record ($records->items) {
- my $fh = $subdir->file($record->uuid . '.html')->openw;
+ open (my $fh, '>',File::Spec->catdir($subdir => $record->uuid.'.html'));
print { $fh } Template::Declare->show('record' => $record);
}
}
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm Fri Nov 21 19:17:33 2008
@@ -2,12 +2,13 @@
package Prophet::CLI::Command::Shell;
use Moose;
extends 'Prophet::CLI::Command';
-use Path::Class 'file';
+use File::Spec;
+use Prophet::Util;
has name => (
is => 'ro',
isa => 'Str',
- default => sub { file($0)->basename },
+ default => sub { Prophet::Util->updir($0)}
);
has term => (
Modified: Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm Fri Nov 21 19:17:33 2008
@@ -1,24 +1,21 @@
package Prophet::CLI::PublishCommand;
use Moose::Role;
-use Path::Class;
use File::Temp ();
-sub tempdir { dir(File::Temp::tempdir(CLEANUP => 1)) }
+sub tempdir { my $dir = File::Temp::tempdir(CLEANUP => 0); warn $dir; return $dir; }
sub publish_dir {
my $self = shift;
my %args = @_;
- my @args;
- push @args, '--recursive';
- push @args, '--verbose' if $self->context->has_arg('verbose');
-
- push @args, '--';
- push @args, dir($args{from})->children;
+ $args{from} .= '/';
- push @args, $args{to};
+ my @args;
+ push @args, '--verbose' if $self->context->has_arg('verbose');
+
+ push @args, '--recursive', '--' , $args{from}, $args{to};
my $rsync = $ENV{RSYNC} || "rsync";
my $ret = system($rsync, @args);
Modified: Prophet/trunk/lib/Prophet/Config.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Config.pm (original)
+++ Prophet/trunk/lib/Prophet/Config.pm Fri Nov 21 19:17:33 2008
@@ -2,7 +2,7 @@
use Moose;
use MooseX::AttributeHelpers;
use File::Spec;
-use Path::Class;
+use Prophet::Util;
has app_handle => (
is => 'ro',
@@ -64,7 +64,7 @@
my $config = {};
for my $file (@config) {
- $self->load_from_file(File::Spec->catfile($file), $config);
+ $self->load_from_file($file => $config);
push @{$self->config_files}, $file;
}
@@ -76,7 +76,7 @@
my $file = shift;
my $config = shift || {};
- for my $line ($self->_slurp($file) ) {
+ for my $line (Prophet::Util->slurp($file) ) {
$line =~ s/\#.*$//; # strip comments
next unless ($line =~ /^(.*?)\s*=\s*(.*)$/);
my $key = $1;
@@ -132,7 +132,7 @@
my @lines;
if ( $self->file_if_exists($file) ) {
- @lines = $self->_slurp($file);
+ @lines = Prophet::Util->slurp($file);
}
open my $fh, '>', $file or die "can't save config to $file: $!";
@@ -157,13 +157,6 @@
return 1;
}
-sub _slurp {
- my $self = shift;
- my $abspath = shift;
- open (my $fh, "<", "$abspath") || die $!;
- return <$fh>;
-}
-
__PACKAGE__->meta->make_immutable;
no Moose;
Modified: Prophet/trunk/lib/Prophet/DatabaseSetting.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/DatabaseSetting.pm (original)
+++ Prophet/trunk/lib/Prophet/DatabaseSetting.pm Fri Nov 21 19:17:33 2008
@@ -14,12 +14,7 @@
is => 'rw',
);
-sub BUILDARGS {
- my $self = shift;
- my $args = $self->SUPER::BUILDARGS(@_);
- $args->{type} ||= '__prophet_db_settings';
- return $args;
-}
+has type => (default => '__prophet_db_settings');
sub BUILD {
my $self = shift;
Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm (original)
+++ Prophet/trunk/lib/Prophet/Record.pm Fri Nov 21 19:17:33 2008
@@ -3,7 +3,6 @@
use MooseX::ClassAttribute;
use Params::Validate;
use Prophet::App; # for require_module. Kinda hacky
-
use constant collection_class => 'Prophet::Collection';
=head1 NAME
@@ -31,8 +30,8 @@
has type => (
is => 'rw',
isa => 'Str',
- required => 1,
predicate => 'has_type',
+ required => 1,
default => sub { undef}
);
Modified: Prophet/trunk/lib/Prophet/Replica/prophet.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/prophet.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica/prophet.pm Fri Nov 21 19:17:33 2008
@@ -4,10 +4,12 @@
use Params::Validate qw(:all);
use LWP::Simple ();
use File::Spec ();
+use File::Path;
use Cwd ();
use Digest::SHA1 qw(sha1_hex);
use File::Find::Rule;
use Data::UUID;
+use Prophet::Util;
use JSON;
use POSIX qw();
@@ -296,7 +298,7 @@
$self->record_cas_dir, $self->changeset_cas_dir,
$self->userdata_dir
) {
- $self->_mkdir(File::Spec->catdir($self->fs_root => $_));
+ mkpath([File::Spec->catdir($self->fs_root => $_)]);
}
@@ -435,7 +437,7 @@
my $index_path = File::Spec->catfile( $self->fs_root, $idx_filename );
my (undef,$parent, $filename) = File::Spec->splitpath($index_path);
- $self->_mkdir($parent);
+ mkpath([$parent]);
open( my $record_index, ">>" . $index_path);
@@ -745,7 +747,8 @@
my $file = File::Spec->catfile( $self->fs_root => $args{'path'} );
my (undef, $parent, $filename) = File::Spec->splitpath($file);
unless ( -d $parent ) {
- $self->_mkdir($parent) || die "Failed to create directory " . $parent;
+ eval { mkpath([$parent])} ;
+ if (my $msg = $@) { die "Failed to create directory " . $parent." - $msg";}
}
open(my $fh, ">$file") || die $!;
@@ -775,24 +778,6 @@
else { return 0 }
}
-sub _mkdir {
- my $self = shift;
- my $path = shift;
- my @parts = File::Spec->splitdir($path);
- my @so_far;
-
-
- for my $part (@parts) {
- push @so_far, $part;
- my $dir = File::Spec->catdir(@so_far);
- next if (-d $dir);
- mkdir ($dir) || die "Failed to create a directory: ".$!;
- }
-
- return 1;
-
-}
-
sub read_file {
my $self = shift;
my ($file) = validate_pos( @_, 1 );
@@ -810,7 +795,7 @@
if ( $self->fs_root ) {
return eval {
local $SIG{__DIE__} = 'DEFAULT';
- $self->_slurp (File::Spec->catfile( $self->fs_root => $file ))
+ Prophet::Util->slurp (File::Spec->catfile( $self->fs_root => $file ))
};
} else { # http replica
return LWP::Simple::get( $self->url . "/" . $file );
@@ -819,15 +804,6 @@
}
-sub _slurp {
- my $self = shift;
- my $abspath = shift;
- open (my $fh, "<", "$abspath") || die $!;
-
- my @lines = <$fh>;
- close $fh;
- return join('', at lines);
-}
sub begin_edit {
my $self = shift;
Modified: Prophet/trunk/lib/Prophet/Test.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test.pm (original)
+++ Prophet/trunk/lib/Prophet/Test.pm Fri Nov 21 19:17:33 2008
@@ -8,12 +8,13 @@
/;
use File::Path 'rmtree';
+use File::Spec;
use File::Temp qw/tempdir tempfile/;
-use Path::Class 'dir';
use Test::Exception;
use IPC::Run3 'run3';
use Params::Validate ':all';
use Scalar::Defer qw/lazy defer force/;
+use Prophet::Util;
use Prophet::CLI;
@@ -166,13 +167,14 @@
our $RUNCNT;
sub _get_perl_cmd {
- my ($tmp, $i) = (Path::Class::File->new($0)->dir, 0);
- while ( !$tmp->subdir('bin')->stat && $i++ < 10 ) {
- $tmp = $tmp->parent;
+ my ($tmp, $i) = (Prophet::Util->updir($0), 0);
+ while ( ! -d File::Spec->catdir($tmp, 'bin') && $i++ < 10 ) {
+ $tmp = Prophet::Util->updir($tmp);
}
- die "couldn't find bin dir" unless $tmp->subdir('bin')->stat;
+
+ my $base_dir = File::Spec->catdir($tmp, 'bin');
+ die "couldn't find bin dir" unless -d $base_dir;
- my $base_dir = $tmp->subdir('bin');
my $script = shift;
my @cmd = ( $^X, ( map {"-I$_"} @INC ) );
push @cmd, '-MDevel::Cover' if $INC{'Devel/Cover.pm'};
@@ -180,7 +182,7 @@
push @cmd, '-d:DProf';
$ENV{'PERL_DPROF_OUT_FILE_NAME'} = 'tmon.out.' . $$ . '.' . $RUNCNT++;
}
- push @cmd, $base_dir->file($script);
+ push @cmd, File::Spec->catdir($base_dir => $script);
return @cmd;
}
@@ -241,7 +243,7 @@
sub repo_path_for {
my $username = shift;
- return dir($REPO_BASE)->subdir($username);
+ return File::Spec->catdir($REPO_BASE => $username);
}
=head2 repo_uri_for $USERNAME
Modified: Prophet/trunk/t/export.t
==============================================================================
--- Prophet/trunk/t/export.t (original)
+++ Prophet/trunk/t/export.t Fri Nov 21 19:17:33 2008
@@ -49,18 +49,18 @@
'content is correct'
);
- my $path = Path::Class::dir->new( tempdir( CLEANUP => ! $ENV{TEST_VERBOSE} ) );
+ my $path = tempdir( CLEANUP => ! $ENV{TEST_VERBOSE} ) ;
run_ok( 'prophet', [ 'export', '--path', $path ] );
my $cli = Prophet::CLI->new;
ok( -d $path, 'found db-uuid root ' . $path );
- ok( -e $path->file('replica-uuid'), 'found replica uuid file' );
+ ok( -e File::Spec->catdir($path => 'replica-uuid'), 'found replica uuid file' );
lives_and {
- is( $path->file('replica-uuid')->slurp, replica_uuid() );
+ is( Prophet::Util->slurp(File::Spec->catdir($path => 'replica-uuid')), replica_uuid() );
};
- ok( -e $path->file('changesets.idx'), 'found changesets index' );
- my $latest = $path->file('latest-sequence-no')->slurp;
+ ok( -e File::Spec->catfile($path => 'changesets.idx'), 'found changesets index' );
+ my $latest = Prophet::Util->slurp(File::Spec->catfile($path => 'latest-sequence-no'));
is( $latest, $cli->handle->latest_sequence_no );
use_ok('Prophet::Replica::prophet');
diag("Checking changesets in $path");
Modified: Prophet/trunk/t/publish-html.t
==============================================================================
--- Prophet/trunk/t/publish-html.t (original)
+++ Prophet/trunk/t/publish-html.t Fri Nov 21 19:17:33 2008
@@ -4,7 +4,7 @@
use Prophet::Test tests => 13;
use Test::Exception;
use File::Temp 'tempdir';
-use Path::Class;
+use File::Spec;
use Params::Validate;
my ($bug_uuid, $pullall_uuid);
@@ -23,25 +23,25 @@
run_ok( 'prophet', [qw(publish --html --to), $alice_published] );
};
-my $dir = dir($alice_published);
+my $dir = $alice_published;
-my $merge_tickets = $dir->subdir('_merge_tickets');
+my $merge_tickets = File::Spec->catdir($dir => '_merge_tickets');
ok(!-e $merge_tickets, "_merge_tickets template directory absent");
-my $bug = $dir->subdir('Bug');
+my $bug = File::Spec->catdir($dir => 'Bug');
ok(-e $bug, "Bug template directory exists");
-my $index = $bug->file('index.html');
+my $index = File::Spec->catfile($bug =>'index.html');
ok(-e $index, "Bug/index.html exists");
-my $bug_template = $bug->file("$bug_uuid.html");
+my $bug_template = File::Spec->catfile($bug => "$bug_uuid.html");
ok(-e $bug_template, "Bug/$bug_uuid.html exists");
-my $index_contents = $index->slurp;
+my $index_contents = Prophet::Util->slurp($index);
like($index_contents, qr/$bug_uuid/, "index contains bug uuid");
like($index_contents, qr/this is a template test/, "index contains bug summary");
-my $bug_contents = $bug_template->slurp;
+my $bug_contents = Prophet::Util->slurp($bug_template);
like($bug_contents, qr/$bug_uuid/, "bug contains bug uuid");
like($bug_contents, qr/this is a template test/, "bug contains bug summary");
Modified: Prophet/trunk/t/publish-pull.t
==============================================================================
--- Prophet/trunk/t/publish-pull.t (original)
+++ Prophet/trunk/t/publish-pull.t Fri Nov 21 19:17:33 2008
@@ -4,7 +4,6 @@
use Prophet::Test tests => 24;
use Test::Exception;
use File::Temp 'tempdir';
-use Path::Class;
use Params::Validate;
my ($bug_uuid, $pullall_uuid);
More information about the Bps-public-commit
mailing list