[Jifty-commit] r6003 - in jifty/trunk: lib/Jifty/Action

Jifty commits jifty-commit at lists.jifty.org
Mon Nov 17 16:04:24 EST 2008


Author: alexmv
Date: Mon Nov 17 16:04:17 2008
New Revision: 6003

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action/Record.pm

Log:
 r39186 at kohr-ah:  chmrr | 2008-11-17 16:02:41 -0500
  * perltidy


Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Mon Nov 17 16:04:17 2008
@@ -149,13 +149,13 @@
 
     # Don't do this twice, it's too expensive
     unless ( $self->_cached_arguments ) {
-        $ARGUMENT_PROTOTYPE_CACHE->{ ref($self) } ||= $self->_build_class_arguments();
-        $self->_cached_arguments( $self->_fill_in_argument_record_data());
+        $ARGUMENT_PROTOTYPE_CACHE->{ ref($self) }
+            ||= $self->_build_class_arguments();
+        $self->_cached_arguments( $self->_fill_in_argument_record_data() );
     }
     return $self->_cached_arguments();
 }
 
-
 sub _fill_in_argument_record_data {
     my $self = shift;
 
@@ -168,28 +168,30 @@
             Scalar::Util::weaken $weakself;
             $arguments->{$field}->{default_value} = defer {
                 my $val = $function->( $weakself->record );
+
                 # If the current value is actually a pointer to
                 # another object, turn it into an ID
-                return $val->id if (blessed($val) and $val->isa('Jifty::Record'));
+                return $val->id
+                    if ( blessed($val) and $val->isa('Jifty::Record') );
                 return $val;
             }
         }
+
         # The record's current value becomes the widget's default value
     }
     return $arguments;
 }
 
-
 sub _build_class_arguments {
     my $self = shift;
 
     # Get ready to rumble
     my $field_info = {};
-    my @columns     = $self->possible_columns;
+    my @columns    = $self->possible_columns;
 
     # we use a while here because we may be modifying the fields on the fly.
     while ( my $column = shift @columns ) {
-        my $info = {};
+        my $info  = {};
         my $field = $column->name;
 
         # Canonicalize the render_as setting for the column
@@ -239,12 +241,16 @@
             if ( UNIVERSAL::isa( $refers_to, 'Jifty::Record' ) ) {
                 $info->{render_as} = $render_as || 'Select';
 
-                $info->{render_as} = 'Text' unless $column->refers_to->enumerable;
+                $info->{render_as} = 'Text'
+                    unless $column->refers_to->enumerable;
             }
 
             # If it's a select box, setup the available values
-            if ( UNIVERSAL::isa( $refers_to, 'Jifty::Record' ) && $info->{render_as} eq 'Select' ) {
-                $info->{'valid_values'} = $self->_default_valid_values( $column, $refers_to );
+            if ( UNIVERSAL::isa( $refers_to, 'Jifty::Record' )
+                && $info->{render_as} eq 'Select' )
+            {
+                $info->{'valid_values'}
+                    = $self->_default_valid_values( $column, $refers_to );
             }
 
             # If the reference is X-to-many instead, skip it
@@ -259,23 +265,28 @@
                 # developer know what he/she is doing.
                 # So we just render it as whatever specified.
 
-                # XXX TODO -  the next line seems to be a "next" which meeant to just fall through the else
-            # next unless $render_as;
+# XXX TODO -  the next line seems to be a "next" which meeant to just fall through the else
+# next unless $render_as;
             }
         }
 
         #########
 
         $info->{'autocompleter'} ||= $self->_argument_autocompleter($column);
-        my ( $validator, $ajax_validates ) = $self->_argument_validator($column);
+        my ( $validator, $ajax_validates )
+            = $self->_argument_validator($column);
         $info->{validator}      ||= $validator;
         $info->{ajax_validates} ||= $ajax_validates;
-        my ( $canonicalizer, $ajax_canonicalizes ) = $self->_argument_canonicalizer($column);
+        my ( $canonicalizer, $ajax_canonicalizes )
+            = $self->_argument_canonicalizer($column);
         $info->{'canonicalizer'}      ||= $canonicalizer;
         $info->{'ajax_canonicalizes'} ||= $ajax_canonicalizes;
 
         # If we're hand-coding a render_as, hints or label, let's use it.
-        for ( qw(render_as label hints max_length mandatory sort_order container documentation)) {
+        for (
+            qw(render_as label hints max_length mandatory sort_order container documentation)
+            )
+        {
             if ( defined( my $val = $column->$_ ) ) {
                 $info->{$_} = $val;
             }
@@ -313,8 +324,6 @@
     }
 }
 
-
-
 sub _argument_validator {
     my $self    = shift;
     my $column  = shift;
@@ -346,14 +355,20 @@
                     qq{Schema validator for $field didn't explain why the value '$value' is invalid}
                 );
             }
-            return ( $self->validation_error( $field => ( $message || _( "That doesn't look right, but I don't know why"))));
+            return (
+                $self->validation_error(
+                    $field => (
+                        $message || _(
+                            "That doesn't look right, but I don't know why")
+                    )
+                )
+            );
             }
     }
 
     return ( $method, $do_ajax );
 }
 
-
 sub _argument_canonicalizer {
     my $self    = shift;
     my $column  = shift;
@@ -363,7 +378,7 @@
 
     # Add a canonicalizer for the column if the record provides one
     if ( $self->record->has_canonicalizer_for_column($field) ) {
-        $do_ajax = 1 unless lc($column->render_as) eq 'checkbox';
+        $do_ajax = 1 unless lc( $column->render_as ) eq 'checkbox';
         $method ||= sub {
             my ( $self, $value ) = @_;
             return $self->record->run_canonicalization_for_column(
@@ -381,36 +396,37 @@
 }
 
 sub _argument_autocompleter {
-    my $self = shift;
+    my $self   = shift;
     my $column = shift;
     my $field  = $column->name;
 
     my $autocomplete;
 
-        # What would the autocomplete method be for this column in the record
-        my $autocomplete_method = "autocomplete_" . $field;
+    # What would the autocomplete method be for this column in the record
+    my $autocomplete_method = "autocomplete_" . $field;
 
-        # Set the autocompleter if the record has one
-        if ( $self->record->can($autocomplete_method) ) {
-            $autocomplete ||= sub {
-                my ( $self, $value ) = @_;
-                my %columns;
-                $columns{$_} = $self->argument_value($_) for grep { $_ ne $field } $self->possible_fields;
-                return $self->record->$autocomplete_method( $value, %columns );
-            };
-        }
+    # Set the autocompleter if the record has one
+    if ( $self->record->can($autocomplete_method) ) {
+        $autocomplete ||= sub {
+            my ( $self, $value ) = @_;
+            my %columns;
+            $columns{$_} = $self->argument_value($_)
+                for grep { $_ ne $field } $self->possible_fields;
+            return $self->record->$autocomplete_method( $value, %columns );
+        };
+    }
 
-        # The column requests an automagically generated autocompleter, which
-        # is baed upon the values available in the field
-        elsif ($column->autocompleted) {
-            # Auto-generated autocompleter
-            $autocomplete ||=  sub {  $self->_default_autocompleter(shift , $field)};
-            
-        }
-        return $autocomplete;
+    # The column requests an automagically generated autocompleter, which
+    # is baed upon the values available in the field
+    elsif ( $column->autocompleted ) {
 
-    }
+        # Auto-generated autocompleter
+        $autocomplete
+            ||= sub { $self->_default_autocompleter( shift, $field ) };
 
+    }
+    return $autocomplete;
+}
 
 sub _default_valid_values {
     my $self      = shift;
@@ -438,9 +454,12 @@
             collection   => $collection
         }
     );
-    unshift @valid, {
+    unshift @valid,
+        {
         display => _('no value'),
-        value   => '' } unless $column->mandatory;
+        value   => ''
+        }
+        unless $column->mandatory;
     return \@valid;
 
 }
@@ -505,10 +524,12 @@
 
 sub possible_columns {
     my $self = shift;
-    return grep { $_->container or (!$_->private and !$_->virtual and $_->type ne "serial") } $self->record->columns;
+    return grep {
+        $_->container
+            or ( !$_->private and !$_->virtual and $_->type ne "serial" )
+    } $self->record->columns;
 }
 
-
 =head2 possible_fields
 
 Returns the list of the L</possible_columns>' names.
@@ -544,27 +565,28 @@
     # Setup the information regarding the event for later publishing
     my $event_info = {};
     $event_info->{as_hash_before} = $self->record->as_hash;
-    $event_info->{record_id} = $self->record->id;
-    $event_info->{record_class} = ref($self->record);
-    $event_info->{action_class} = ref($self);
-    $event_info->{action_arguments} = $self->argument_values; # XXX does this work?
+    $event_info->{record_id}      = $self->record->id;
+    $event_info->{record_class}   = ref( $self->record );
+    $event_info->{action_class}   = ref($self);
+    $event_info->{action_arguments}
+        = $self->argument_values;    # XXX does this work?
     $event_info->{current_user_id} = $self->current_user->id || 0;
     return ($event_info);
 }
 
 sub _setup_event_after_action {
-    my $self = shift;
+    my $self       = shift;
     my $event_info = shift;
 
-    unless (defined $event_info->{record_id}) {
-        $event_info->{record_id} = $self->record->id;
-        $event_info->{record_class} = ref($self->record);
+    unless ( defined $event_info->{record_id} ) {
+        $event_info->{record_id}    = $self->record->id;
+        $event_info->{record_class} = ref( $self->record );
         $event_info->{action_class} = ref($self);
     }
 
     # Add a few more bits about the result
-    $event_info->{result} = $self->result;    
-    $event_info->{timestamp} = time(); 
+    $event_info->{result}        = $self->result;
+    $event_info->{timestamp}     = time();
     $event_info->{as_hash_after} = $self->record->as_hash;
 
     # Publish the event


More information about the Jifty-commit mailing list