[Bps-public-commit] r12508 - in Prophet/branches/moose: .

jesse at bestpractical.com jesse at bestpractical.com
Sun May 18 10:53:55 EDT 2008


Author: jesse
Date: Sun May 18 10:53:55 2008
New Revision: 12508

Modified:
   Prophet/branches/moose/   (props changed)
   Prophet/branches/moose/Makefile.PL
   Prophet/branches/moose/lib/Prophet/CLI.pm

Log:
 r31692 at 31b:  jesse | 2008-05-18 21:05:45 +0800
 * Mooseified Prophet::CLI
 * Extracted 'record related' CLI command stuff into a moose role
      Wants review


Modified: Prophet/branches/moose/Makefile.PL
==============================================================================
--- Prophet/branches/moose/Makefile.PL	(original)
+++ Prophet/branches/moose/Makefile.PL	Sun May 18 10:53:55 2008
@@ -23,7 +23,7 @@
 requires('File::Find::Rule');
 requires('Proc::InvokeEditor');
 requires('Scalar::Defer');
-requires('Moose'); # Moose::Util::TypeConstraints
+requires('Moose'); # Moose::Util::TypeConstraints Moose::Role
 requires('MooseX::AttributeHelpers');
 requires('MooseX::ClassAttribute');
 

Modified: Prophet/branches/moose/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/branches/moose/lib/Prophet/CLI.pm	(original)
+++ Prophet/branches/moose/lib/Prophet/CLI.pm	Sun May 18 10:53:55 2008
@@ -215,20 +215,26 @@
     return $ret;
 }
 
-package Prophet::CLI::Command;
-
-use base qw/Class::Accessor/;
-
-__PACKAGE__->mk_accessors(qw/cli record_class command type uuid/);
-
-# XXX type, uuid are only for record commands
+package Prophet::CLI::RecordCommand;
+use Moose::Role;
 
-sub fatal_error {
-    my $self   = shift;
-    my $reason = shift;
-    die $reason . "\n";
+has type => (
+    is => 'rw',
+    isa => 'Str',
+    required => 0
+);
+
+has uuid => (
+    is => 'rw',
+    isa => 'Str',
+    required => 0
+);
+
+has record_class => (
+    is => 'rw',
+    isa => 'Prophet::Record',
+);
 
-}
 
 sub _get_record {
     my $self = shift;
@@ -255,6 +261,25 @@
     return 'Prophet::Record';
 }
 
+
+
+package Prophet::CLI::Command;
+use Moose;
+
+has cli => (
+    is => 'rw',
+    isa => 'Prophet::CLI',
+    weak_ref => 1);
+
+
+sub fatal_error {
+    my $self   = shift;
+    my $reason = shift;
+    die $reason . "\n";
+
+}
+
+
 sub args {
     shift->cli->args(@_);
 }
@@ -335,7 +360,14 @@
 }
 
 package Prophet::CLI::Command::Create;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
+
+use Moose;
+extends 'Prophet::CLI::Command';
+with 'Prophet::CLI::RecordCommand';
+
+has +uuid => ( required => 0);
 
 sub run {
     my $self   = shift;
@@ -352,8 +384,10 @@
 }
 
 package Prophet::CLI::Command::Search;
-use base qw/Prophet::CLI::Command/;
-
+use Moose;
+extends 'Prophet::CLI::Command';
+with 'Prophet::CLI::RecordCommand';
+has +uuid => ( required => 0);
 
 sub get_collection_object {
     my $self = shift;
@@ -400,7 +434,10 @@
 }
 
 package Prophet::CLI::Command::Update;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
+use Moose;
+with 'Prophet::CLI::RecordCommand';
 
 sub edit_record {
     my $self   = shift;
@@ -434,8 +471,11 @@
 }
 
 package Prophet::CLI::Command::Delete;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
 
+use Moose;
+with 'Prophet::CLI::RecordCommand';
 sub run {
     my $self = shift;
 
@@ -451,7 +491,11 @@
 }
 
 package Prophet::CLI::Command::Show;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
+use Moose;
+with 'Prophet::CLI::RecordCommand';
+
 
 sub run {
     my $self = shift;
@@ -470,7 +514,8 @@
 }
 
 package Prophet::CLI::Command::Merge;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
 
 sub run {
 
@@ -523,7 +568,8 @@
 }
 
 package Prophet::CLI::Command::Push;
-use base qw/Prophet::CLI::Command::Merge/;
+use Moose;
+extends 'Prophet::CLI::Command::Merge';
 
 sub run {
     my $self = shift;
@@ -538,7 +584,8 @@
 }
 
 package Prophet::CLI::Command::Export;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
 
 sub run {
     my $self = shift;
@@ -547,7 +594,8 @@
 }
 
 package Prophet::CLI::Command::Pull;
-use base qw/Prophet::CLI::Command::Merge/;
+use Moose;
+extends 'Prophet::CLI::Command::Merge';
 
 sub run {
 
@@ -562,7 +610,8 @@
 }
 
 package Prophet::CLI::Command::Server;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
 
 sub run {
 
@@ -576,13 +625,12 @@
 }
 
 package Prophet::CLI::Command::NotFound;
-use base qw/Prophet::CLI::Command/;
+use Moose;
+extends 'Prophet::CLI::Command';
 
 sub run {
     my $self = shift;
-    $self->fatal_error( "The command you ran, '"
-            . ($self->command || '')
-            . "', could not be found. Perhaps running '$0 help' would help?" );
+    $self->fatal_error( "The command you ran could not be found. Perhaps running '$0 help' would help?" );
 }
 
 1;



More information about the Bps-public-commit mailing list