[Jifty-commit] r3585 - in jifty/trunk: lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Jun 29 19:48:16 EDT 2007


Author: alexmv
Date: Fri Jun 29 19:48:14 2007
New Revision: 3585

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

Log:
 r19971 at zoq-fot-pik:  chmrr | 2007-06-29 19:46:25 -0400
  * Move pulling action defaults from action in request into the
    action's new, instead of a "private" argument.
  * Remove an extra place where we default the moniker to
    _generate_moniker
  * A bunch of POD (re)wrapping.


Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Fri Jun 29 19:48:14 2007
@@ -36,7 +36,7 @@
 See also L<Jifty::Action::Record> for data-oriented actions, 
 L<Jifty::Result> for how to return values from actions.
 
-See L<Jifty::Param::Schema> for more details on the declarative 
+See L<Jifty::Param::Schema> for more details on the declarative
 syntax.
 
 See L<Jifty::Manual::Actions> for examples of using actions.
@@ -57,7 +57,8 @@
 
 B<Do not call this directly>; always go through C<< Jifty->web->new_action >>! 
 
-This method constructs a new action. Subclasses who need do custom initialization should start with:
+This method constructs a new action. Subclasses who need do custom
+initialization should start with:
 
     my $class = shift;
     my $self = $class->SUPER::new(@_)
@@ -81,29 +82,20 @@
 =item arguments
 
 A hash reference of default values for the
-L<arguments|Jifty::Manual::Glossary/argument> of the action.  Defaults to
-none.
+L<arguments|Jifty::Manual::Glossary/argument> of the action.  Defaults
+to none.
 
 =item sticky_on_failure
 
 A boolean value that determines if the form fields are
-L<sticky|Jifty::Manual::Glossary/sticky> when the action fails.  Defaults to
-true.
+L<sticky|Jifty::Manual::Glossary/sticky> when the action fails.
+Defaults to true.
 
 =item sticky_on_success
 
 A boolean value that determines if the form fields are
-L<sticky|Jifty::Manual::Glossary/sticky> when the action succeeds.  Defaults
-to false.
-
-=begin private
-
-=item request_arguments
-
-A hashref of arguments passed in as part of the
-L<Jifty::Request>. Internal use only.
-
-=end private
+L<sticky|Jifty::Manual::Glossary/sticky> when the action succeeds.
+Defaults to false.
 
 =back
 
@@ -127,13 +119,16 @@
         $self->_get_current_user();
     }
 
-    if ($args{'moniker'}) {
-        $self->moniker($args{'moniker'});
-    } else {
-        $self->moniker($self->_generate_moniker);
-    }
+    $self->moniker($args{'moniker'} || $self->_generate_moniker);
     $self->order($args{'order'});
 
+    my $action_in_request = Jifty->web->request->action( $self->moniker );
+    # Fields explicitly passed to new_action take precedence over those passed
+    # from the request; we read from the request to implement "sticky fields".
+    if ( $action_in_request and $action_in_request->arguments ) {
+        $args{'request_arguments'} = $action_in_request->arguments;
+    }
+
     $self->argument_values( { %{ $args{'request_arguments' } }, %{ $args{'arguments'} } } );
 
     # Keep track of whether arguments came from the request, or were
@@ -153,11 +148,12 @@
 
 =head2 _generate_moniker 
 
-Construct a moniker for a new (or soon-to-be-constructed) action that did not have
-an explicit moniker specified.  The algorithm is simple: We snapshot the call stack,
-prefix it with the action class, and then append it with an per-request autoincrement
-counter in case the same class/stack is encountered twice, which can happen if the
-programmer placed a C<new_action> call inside a loop.
+Construct a moniker for a new (or soon-to-be-constructed) action that
+did not have an explicit moniker specified.  The algorithm is simple:
+We snapshot the call stack, prefix it with the action class, and then
+append it with an per-request autoincrement counter in case the same
+class/stack is encountered twice, which can happen if the programmer
+placed a C<new_action> call inside a loop.
 
 Monikers generated this way are guaranteed to work across requests.
 
@@ -1135,9 +1131,13 @@
 
 =head2 Canonicalization
 
-If you wish to have the data in a field normalized into a particular format (such as changing a date into YYYY-MM-DD format, adding commas to numbers, capitalizing words, or whatever you need) you can do so using a canonicalizer. 
+If you wish to have the data in a field normalized into a particular
+format (such as changing a date into YYYY-MM-DD format, adding commas
+to numbers, capitalizing words, or whatever you need) you can do so
+using a canonicalizer.
 
-This is just a method titled C<canonicalize_FIELD> where C<FIELD> is the name of the field be normalized. Here is an example:
+This is just a method titled C<canonicalize_FIELD> where C<FIELD> is
+the name of the field be normalized. Here is an example:
 
   sub canonicalize_foo {
       my ($self, $value) = @_;
@@ -1148,21 +1148,28 @@
       return $normal_form;
   }
 
-In this case, all values in the "foo" field will be changed into lower case.
+In this case, all values in the "foo" field will be changed into lower
+case.
 
-While doing this you might also want to call the L</canonicalization_note> to inform the client of the modification:
+While doing this you might also want to call the
+L</canonicalization_note> to inform the client of the modification:
 
   my $normal_form = lc($value);
   $self->canonicalization_note( 
       foo => _('Foo values are always in lowercase.'));
 
-If the "foo" field has "ajax canoncalizes" set in the action schema, then this process will be performed automatically as the form is being filled without reloading the page.
+If the "foo" field has "ajax canoncalizes" set in the action schema,
+then this process will be performed automatically as the form is being
+filled without reloading the page.
 
 =head2 Validation
 
-If a value must follow a certain format, you can provide a validation method for fields to make sure that no value enters the database until it is in a valid form.
+If a value must follow a certain format, you can provide a validation
+method for fields to make sure that no value enters the database until
+it is in a valid form.
 
-A validation method is one named C<validate_FIELD> where C<FIELD> is the name of the field being checked. Here is an example:
+A validation method is one named C<validate_FIELD> where C<FIELD> is
+the name of the field being checked. Here is an example:
 
   sub validate_foo {
       my ($self, $value) = @_;
@@ -1182,15 +1189,26 @@
       return 1;
   }
 
-Here the "foo" field should not contain uppercase letters and must not contain the characters '-', '*', '+', or '?'. You can use L</validation_error> and L</validation_warning> to return the results of your validation to the user or simply return 1 to indicate a valid value.
+Here the "foo" field should not contain uppercase letters and must not
+contain the characters '-', '*', '+', or '?'. You can use
+L</validation_error> and L</validation_warning> to return the results
+of your validation to the user or simply return 1 to indicate a valid
+value.
 
-If you just have a list of valid values, you may want to use the C<valid_values> schema parameter to perform this task instead.
+If you just have a list of valid values, you may want to use the
+C<valid_values> schema parameter to perform this task instead.
 
 =head2 Autocompletion
 
-Autocompletion provides a way of suggesting choices to the client based upon partial data entry. This doesn't necessarily force the client to use one of the choices given but gives hints in an application specific way.
-
-To create an autocompletion field, you implement a method named C<autocomplete_FIELD> where C<FIELD> is the field to autocomplete. This is generally done with fields rendered as 'Text'. Here is an example:
+Autocompletion provides a way of suggesting choices to the client
+based upon partial data entry. This doesn't necessarily force the
+client to use one of the choices given but gives hints in an
+application specific way.
+
+To create an autocompletion field, you implement a method named
+C<autocomplete_FIELD> where C<FIELD> is the field to
+autocomplete. This is generally done with fields rendered as
+'Text'. Here is an example:
 
   sub autocomplete_foo {
       my ($self, $value) = @_;
@@ -1209,16 +1227,25 @@
       return map { $_->name } @{ $foos->items_array_ref };
   }
 
-In this example, the "foo" field is autocompleted from names matched from the C<MyApp::Model::Foo> table. The match, in this case, matches any substring found in the database. I could have matched any item that starts with the string, ends with the string, matches other fields than the one returned, etc. It's up to you to decide.
-
-Note also that I have untainted the value coming in to make sure a malicious user doesn't get anyway. You should always perform a check like this when data is coming in from an outside source.
-
-If you need a more complicated solution, you can return the autocompletion values as a list of hash references containing the keys C<value> and (optionally) C<label>:
+In this example, the "foo" field is autocompleted from names matched
+from the C<MyApp::Model::Foo> table. The match, in this case, matches
+any substring found in the database. I could have matched any item
+that starts with the string, ends with the string, matches other
+fields than the one returned, etc. It's up to you to decide.
+
+Note also that I have untainted the value coming in to make sure a
+malicious user doesn't get anyway. You should always perform a check
+like this when data is coming in from an outside source.
+
+If you need a more complicated solution, you can return the
+autocompletion values as a list of hash references containing the keys
+C<value> and (optionally) C<label>:
 
   return map { { value => $_->name, label => $_->label } }
             @{ $foos->items_array_ref };
 
-In this case, the labels will be shown to the client, but the selected value would be returned to your application.
+In this case, the labels will be shown to the client, but the selected
+value would be returned to your application.
 
 =cut
 
@@ -1226,7 +1253,8 @@
 
 =head1 SEE ALSO
 
-L<Jifty>, L<Jifty::API>, L<Jifty::Action::Record>, L<Jifty::Result>, L<Jifty::Param::Schema>, L<Jifty::Manual::Actions>
+L<Jifty>, L<Jifty::API>, L<Jifty::Action::Record>, L<Jifty::Result>,
+L<Jifty::Param::Schema>, L<Jifty::Manual::Actions>
 
 =head1 LICENSE
 

Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Fri Jun 29 19:48:14 2007
@@ -457,7 +457,9 @@
 
 =head3 new_action class => CLASS, moniker => MONIKER, order => ORDER, arguments => PARAMHASH
 
-Creates a new action (an instance of a subclass of L<Jifty::Action>). The named arguments passed to this method are passed on to the C<new> method of the action named in C<CLASS>.
+Creates a new action (an instance of a subclass of
+L<Jifty::Action>). The named arguments passed to this method are
+passed on to the C<new> method of the action named in C<CLASS>.
 
 =head3 Arguments
 
@@ -522,17 +524,6 @@
     $class = Jifty->api->qualify($class);
 
     my $loaded = Jifty::Util->require( $class );
-    $args{moniker} ||= ($loaded ? $class : 'Jifty::Action')->_generate_moniker;
-
-    my $action_in_request = $self->request->action( $args{moniker} );
-
-    # Fields explicitly passed to new_action take precedence over those passed
-    # from the request; we read from the request to implement "sticky fields".
-    #
-    if ( $action_in_request and $action_in_request->arguments ) {
-        $args{'request_arguments'} = $action_in_request->arguments;
-    }
-
     # The implementation class is provided by the client, so this
     # isn't a "shouldn't happen"
     return unless $loaded;


More information about the Jifty-commit mailing list