From: Chris W. <la...@us...> - 2005-03-02 15:32:33
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25930/OpenInteract2 Modified Files: Action.pm Log Message: OIN-135: add property 'url_additional' and method in execute() to match up the names from 'url_additional' with the values from the request's 'param_url_additional()' method Index: Action.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Action.pm,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** Action.pm 26 Feb 2005 05:56:20 -0000 1.69 --- Action.pm 2 Mar 2005 15:32:23 -0000 1.70 *************** *** 55,58 **** --- 55,59 ---- template_source => 'Template(s) to use to generate task content; can be specified per-task', cache_param => 'Parameters to use when caching contnent', + url_additional => 'Parameter names to which additional URL parameters get assigned; may be segmented by task', ); *************** *** 270,274 **** $log->debug( "Action $item_desc security checked, continuing" ); ! # Check cache and return if found my $cached_content = $self->_check_cache; --- 271,291 ---- $log->debug( "Action $item_desc security checked, continuing" ); ! # Assign any additional URL parameters -- do this before the cache ! # check to ensure that's consistent (it discriminates based on ! # param values) ! ! my @url_params = $self->_get_url_additional_names; ! if ( scalar @url_params ) { ! my $request = CTX->request; ! if ( $request ) { ! my @url_values = $request->param_url_additional; ! my $param_count = 0; ! foreach my $value ( @url_values ) { ! next unless ( $url_params[ $param_count ] ); ! $self->param( $url_params[ $param_count ], $value ); ! $param_count++; ! } ! } ! } my $cached_content = $self->_check_cache; *************** *** 321,324 **** --- 338,367 ---- } + sub _get_url_additional_names { + my ( $self ) = @_; + my $additional = $self->url_additional; + return unless ( $additional ); + my ( @items ); + my $task = $self->task; + if ( ref $additional eq 'ARRAY' ) { + @items = @{ $additional }; + } + elsif ( ref $additional eq 'HASH' ) { + my $base = $additional->{ $task } || + $additional->{DEFAULT} || + $additional->{default}; + if ( $base and ref $base eq 'ARRAY') { + @items = @{ $base }; + } + elsif ( $base ) { + @items = ( $base ); + } + } + else { + @items = ( $additional ); + } + return @items; + } + ######################################## # TASK *************** *** 1889,1892 **** --- 1932,1996 ---- url_alt = Noticias + B<url_additional( \@ or \% )> + + Action parameter names to associate with additional URL parameters + pulled from the request's C<param_url_additional()> method. This + association is done in C<execute()>. + + If specified as an arrayref we associate the parameters no matter what + task is called on the action. If specified as a hashref you can + specify parameter names per-task, using DEFAULT as a catch-all. + + Examples: + + # the value of the first additional URL parameter is assigned to the + # action parameter 'news_id' + [news] + ... + url_additional = news_id + + # Given URL: + URL: http://foo/news/display/22/ + + # Task implementation + sub display { + my ( $self ) = @_; + my $id = $self->param( 'news_id' ); + # $id is '22' since we pulled it from the first URL parameter + } + + # for all actions but 'archive' the value of the first additional URL + # parameter is assigned to the action parameter 'news_id'; for + # archive we assign them to 'search_year', 'search_month' and + # 'search_day' + [news] + ... + [news url_additional] + DEFAULT = news_id + archive = search_year + archive = search_month + archive = search_day + + # Given URL: + http://foo/news/remove/1099/ + + # Task implementation matching 'DEFAULT' + sub remove { + my ( $self ) = @_; + my $id = $self->param( 'news_id' ); + # $id is '1099' since we pulled it from the first URL parameter + } + + # Given URL: + http://foo/news/archive/2005/7/ + + sub archive { + my ( $self ) = @_; + my $year = $self->param( 'search_year' ); + my $month = $self->param( 'search_month' ); + my $day = $self->param( 'search_day' ); + # $year = 2005; $month = 7; $day is undef + } + B<message_name> ($) *************** *** 2360,2366 **** Most actions do not implement this method, instead implementing a task ! and using the base class implementation of C<execute()> to lookup the ! task and perform the necessary security checks and caching. (Learn ! about caching in L<OpenInteract2::Manual::Caching>.) Returns: content generated by the action --- 2464,2493 ---- Most actions do not implement this method, instead implementing a task ! and using the base class implementation of C<execute()> to: ! ! =over 4 ! ! =item * ! ! lookup the task ! ! =item * ! ! perform the necessary security checks ! ! =item * ! ! match up additional URL parameters from the request to action parameters ! ! =item * ! ! check the cache for matching content (More about caching in ! L<OpenInteract2::Manual::Caching>.) ! ! =item * ! ! after the content has been generated, store the content in the cache as necessary ! ! =back Returns: content generated by the action *************** *** 2473,2476 **** --- 2600,2609 ---- See L<PROPERTIES> for the list of properties in each action. + B<property_info()> + + Get a hash of all property names and descriptions -- used in a + management task so you can easily lookup properties without jumping + into the (fairly long) docs. + B<param_from_request( @param_names )> |