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

sartak at bestpractical.com sartak at bestpractical.com
Thu Jul 17 23:56:50 EDT 2008


Author: sartak
Date: Thu Jul 17 23:56:50 2008
New Revision: 14251

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

Log:
 r64551 at onn:  sartak | 2008-07-17 23:56:32 -0400
 Let subclasses define default properties for records


Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm	(original)
+++ Prophet/trunk/lib/Prophet/Record.pm	Thu Jul 17 23:56:50 2008
@@ -149,6 +149,8 @@
     my $self = shift;
     my %args = validate( @_, { props => 1 } );
     my $uuid = $UUIDGEN->create_str;
+
+    $self->default_props($args{'props'});
     $self->canonicalize_props( $args{'props'} );
     $self->validate_props( $args{'props'} ) or return undef;
 
@@ -331,6 +333,23 @@
     return 1;
 }
 
+sub default_props {
+    my $self   = shift;
+    my $props  = shift;
+
+    my @methods = grep { $_->{name} =~ /^default_prop_/ } $self->meta->compute_all_applicable_methods;
+
+    for my $method_data (@methods) {
+        my ($key) = $method_data->{name} =~ /^default_prop_(.+)$/;
+        my $sub   = $method_data->{code};
+
+        $props->{$key} = $sub->( $self, props => $props)
+            if !defined($props->{$key});
+    }
+
+    return 1;
+}
+
 =head2 format_summary
 
 returns a formated string that is the summary for the record.



More information about the Bps-public-commit mailing list