[Bps-public-commit] r11970 - in Prophet/trunk: .

jesse at bestpractical.com jesse at bestpractical.com
Tue Apr 29 19:39:36 EDT 2008


Author: jesse
Date: Tue Apr 29 19:39:36 2008
New Revision: 11970

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/App.pm
   Prophet/trunk/lib/Prophet/CLI.pm
   Prophet/trunk/lib/Prophet/Record.pm

Log:
 r30248 at 254:  jesse | 2008-04-29 19:39:31 -0400
 * Extract out the require_module sub to Prophet::App (really, it wants to be in Prophet::Util); Work to get reference types working


Modified: Prophet/trunk/lib/Prophet/App.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/App.pm	(original)
+++ Prophet/trunk/lib/Prophet/App.pm	Tue Apr 29 19:39:36 2008
@@ -70,5 +70,18 @@
 }
 
 
+sub require_module {
+    my $self = shift;
+    my $class = shift;
+    $class->require;
+    if (my $msg = $@) {
+        my $class_path = $class .".pm";
+        $class_path =~ s/::/\//g;
+        my $ok_err= "Can't locate $class_path";
+        die $msg if $msg !~  qr/^$ok_err/;
+    }
+    $@ = '';
+}
+
 
 1;

Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI.pm	Tue Apr 29 19:39:36 2008
@@ -51,7 +51,7 @@
     my ( $self, $type, $record_class ) = @_;
     my $cmd = shift @ARGV or die "record subcommand required";
 
-    $record_class->require || die $@;
+    Prophet::App->require_module($record_class);
     return $self->_handle_reference_command( $record_class,
         $record_class->REFERENCES->{$cmd} )
         if ( $record_class->REFERENCES->{$cmd} );
@@ -112,12 +112,7 @@
 sub _try_to_load_cmd_class {
     my $self = shift;
     my $class = shift;
-    $class->require;
-    if (my $msg = $@) {
-        my $class_path = $class .".pm";
-        $class_path =~ s/::/\//g;
-        die $msg if $msg !~ /Can't locate $class_path/;
-    }
+    Prophet::App->require_module($class);
     return $class if ( $class->isa('Prophet::CLI::Command') );
 
     return undef;
@@ -139,11 +134,13 @@
 
     $self->primary_commands( \@primary );
 
-    %{ $self->{'args'} } = @ARGV;
-    for my $name ( keys %{ $self->{'args'} } ) {
+    while (my $name = shift @ARGV) { 
         die "$name doesn't look like --prop-name" if ( $name !~ /^--/ );
-        $name =~ /^--(.*)$/;
-        $self->{args}->{$1} = delete $self->{'args'}->{$name};
+        my $val;
+
+        ($name,$val)= split(/=/,$name,2) if ($name =~/=/);
+        $name =~ s/^--//;
+        $self->{'args'}->{$name} =  ($val || shift @ARGV);
     }
 
 }
@@ -207,9 +204,10 @@
 
 sub _get_record {
     my $self = shift;
-     my $args = { handle => $self->cli->app_handle->handle, type => $self->type } ;
-    if ( $self->record_class ) {
-        return $self->record_class->new( $args);
+     my $args = { handle => $self->cli->app_handle->handle, type => $self->type };
+    if (my $class =  $self->record_class ) {
+        Prophet::App->require_module($class);
+        return $class->new( $args);
     } elsif ( $self->type ) {
         return $self->_type_to_record_class( $self->type )->new($args);
     } else { Carp::confess("I was asked to get a record object, but I have neither a type nor a record class")}
@@ -220,11 +218,11 @@
     my $self = shift;
     my $type = shift;
     my $try = $self->cli->app_class . "::Model::" . ucfirst( lc($type) );
-    $try->require;    # don't care about fails
+    Prophet::App->require_module($try);    # don't care about fails
     return $try if ( $try->isa('Prophet::Record') );
 
     $try = $self->cli->app_class . "::Record";
-    $try->require;
+    Prophet::App->require_module($try);    # don't care about fails
     return $try if ( $try->isa('Prophet::Record') );
     return 'Prophet::Record';
 }
@@ -257,7 +255,7 @@
     my $self = shift;
 
     my $record = $self->_get_record;
-    $record->collection_class->require;
+    Prophet::App->require_module($record->collection_class);
     my $records = $record->collection_class->new(
         handle => $self->app_handle->handle,
         type   => $self->type

Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm	(original)
+++ Prophet/trunk/lib/Prophet/Record.pm	Tue Apr 29 19:39:36 2008
@@ -26,6 +26,8 @@
 use Params::Validate;
 use Data::UUID;
 use List::MoreUtils qw/uniq/;
+use Prophet::App; # for require_module. Kinda hacky
+
 my $UUIDGEN = Data::UUID->new();
 
 use constant collection_class => 'Prophet::Collection';
@@ -56,6 +58,7 @@
 
 sub register_reference {
     my ( $class, $accessor, $foreign_class, @args ) = @_;
+    $foreign_class->require();
     if ( $foreign_class->isa('Prophet::Collection') ) {
         return $class->register_collection_reference(
             $accessor => $foreign_class,
@@ -82,9 +85,13 @@
     my ( $class, $accessor, $collection_class, @args ) = @_;
     my %args = validate( @args, { by => 1 } );
     no strict 'refs';
+
+    Prophet::App->require_module($collection_class->record_class);
+    
+    
     *{ $class . "::$accessor" } = sub {
         my $self = shift;
-        my $collection = $collection_class->new( handle => $self->handle, type => $collection_class->record_class );
+        my $collection = $collection_class->new( handle => $self->handle, type => $collection_class->record_class->record_type );
         $collection->matching( sub { $_[0]->prop( $args{by} ) eq $self->uuid } );
         return $collection;
     };



More information about the Bps-public-commit mailing list