From: Chris W. <la...@us...> - 2005-02-13 20:15:23
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32044/lib/OpenInteract2 Modified Files: Action.pm Log Message: add OpenInteract2::ParamContainer to ISA, remove old methods and modify docs to reflect Index: Action.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Action.pm,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Action.pm 24 Jan 2005 16:54:28 -0000 1.66 --- Action.pm 13 Feb 2005 20:15:15 -0000 1.67 *************** *** 4,8 **** use strict; ! use base qw( Class::Accessor::Fast Class::Observable Class::Factory Exporter ); use Log::Log4perl qw( get_logger ); use OpenInteract2::Constants qw( :log :template ); --- 4,8 ---- use strict; ! use base qw( OpenInteract2::ParamContainer Class::Accessor::Fast Class::Observable Class::Factory Exporter ); use Log::Log4perl qw( get_logger ); use OpenInteract2::Constants qw( :log :template ); *************** *** 859,924 **** # PARAMS ! sub param_assign { ! my ( $self, $params ) = @_; ! return unless ( ref $params eq 'HASH' ); ! while ( my ( $key, $value ) = each %{ $params } ) { ! next if ( $PROPS{ $key } ); ! next unless ( defined $value ); # TODO: Set empty values? ! $self->param( $key, $value ); ! } ! return $self; ! } ! ! ! sub param { ! my ( $self, $key, $value ) = @_; ! return \%{ $self->{params} } unless ( $key ); ! if ( defined $value ) { ! $self->{params}{ $key } = $value; ! } ! if ( ref $self->{params}{ $key } eq 'ARRAY' ) { ! return ( wantarray ) ! ? @{ $self->{params}{ $key } } ! : $self->{params}{ $key }; ! } ! return ( wantarray ) ! ? ( $self->{params}{ $key } ) ! : $self->{params}{ $key }; ! } ! ! sub param_add { ! my ( $self, $key, @values ) = @_; ! return undef unless ( $key ); ! my $num_values = scalar @values; ! return $self->{params}{ $key } unless ( scalar @values ); ! if ( my $existing = $self->{params}{ $key } ) { ! my $typeof = ref( $existing ); ! if ( $typeof eq 'ARRAY' ) { ! push @{ $self->{params}{ $key } }, @values; ! } ! elsif ( ! $typeof ) { ! $self->{params}{ $key } = [ $existing, @values ]; ! } ! else { ! oi_error "Cannot add $num_values values to parameter [$key] ", ! "since the parameter is defined as a [$typeof] to ", ! "which I cannot reliably add values."; ! } ! } ! else { ! if ( $num_values == 1 ) { ! $self->{params}{ $key } = $values[0]; ! } ! else { ! $self->{params}{ $key } = [ @values ]; ! } ! } ! return $self->param( $key ); ! } ! ! sub param_clear { ! my ( $self, $key ) = @_; ! return delete $self->{params}{ $key }; ! } sub param_from_request { --- 859,863 ---- # PARAMS ! sub get_skip_params { return %PROPS } sub param_from_request { *************** *** 976,985 **** my ( $self, $param_name, $message_key, @key_args ) = @_; $log ||= get_logger( LOG_ACTION ); ! if ( $message_key and $self->param($message_key) ) { my $language_handle = CTX->request->language_handle; $log->is_debug && $log->debug( "Creating message from '$message_key' field '". $self->param($message_key) ."' with args '@key_args'\n" ); ! my $msg = $language_handle->maketext( $self->param($message_key), @key_args ); return $msg if ( $msg ); } --- 915,924 ---- my ( $self, $param_name, $message_key, @key_args ) = @_; $log ||= get_logger( LOG_ACTION ); ! if ( $message_key and $self->param( $message_key ) ) { my $language_handle = CTX->request->language_handle; $log->is_debug && $log->debug( "Creating message from '$message_key' field '". $self->param($message_key) ."' with args '@key_args'\n" ); ! my $msg = $language_handle->maketext( $self->param( $message_key ), @key_args ); return $msg if ( $msg ); } *************** *** 2217,2221 **** C<\%values> that are not action properties will be set into the action parameters, also overriding the values from the action table. (See ! C<param()> below.) =item 2. --- 2156,2160 ---- C<\%values> that are not action properties will be set into the action parameters, also overriding the values from the action table. (See ! L<OpenInteract2::ParamContainer>.) =item 2. *************** *** 2469,2472 **** --- 2408,2414 ---- =head2 Object Property and Parameter Methods + See L<OpenInteract2::ParamContainer> for discussion of the C<param()>, + C<param_add()>, C<param_clear()> and C<param_assign()> methods. + B<property_assign( \%properties )> *************** *** 2518,2584 **** See L<PROPERTIES> for the list of properties in each action. - B<param_assign( \%params )> - - Assigns all items from C<\%params> that are not valid properties to - the action as parameters. - - Currently we only set parameters for which there is a defined value in - C<\%params>. - - Returns: action object (C<$self>) - - B<param( [ $key, $value ] )> - - Get/set action parameters. This can be called in three ways: - - my $params = $action->param; # $params is hashref - my $value = $action->param( $name ); # $value is any type of scalar - $action->param( $name, $new_value ); - my ( @params ) = $action->param( $name ); # ...context senstive - - Returns: if called without arguments, returns a copy of the hashref of - parameters attached to the action (changes made to the hashref will - not affect the action); if called with one or two arguments, returns - the context-sensitve new value of the parameter C<$name>. - - B<param_add( $key, @values )> - - Adds (rather than replaces) the values C<@values> to the parameter - C<$key>. If there is a value already set for C<$key>, or if you pass - multiple values, it is turned into an array reference and C<@values> - C<push>ed onto the end. If there is no value already set and you only - pass a single value it acts like the call to C<param( $key, $value )>. - - This is useful for potentially multivalue parameters, such as the - often-used 'error_msg' and 'status_msg'. You can still access the - values with C<param()> in context: - - $action->param( error_msg => "Ooops I..." ); - $action->param_add( error_msg => "did it again" ); - my $full_msg = join( ' ', $action->param( 'error_msg' ) ); - # $full_msg = 'Ooops I... did it again' - - $action->param( error_msg => "Ooops I..." ); # Set to value - $action->param_add( error_msg => "did it again" ); # ...add new value to existing - $action->param( error_msg => 'and again' ); # ...replace the earlier values entirely - my $full_msg = join( ' ', $action->param( 'error_msg' ) ); - # $full_msg = 'and again' - - $action->param( error_msg => "Ooops I..." ); - $action->param_add( error_msg => "did it again" ); - my $messages = $action->param( 'error_msg' ); - # $messages->[0] = 'Ooops I...' - # $messages->[1] = 'did it again' - - Returns: Context senstive value in of C<$key> - - B<param_clear( $key )> - - Removes all parameter values defined by C<$key>. This is the only way - to remove a parameter. - - Returns: value(s) previously set for the parameter C<$key>, - non-context sensitive. - B<param_from_request( @param_names )> --- 2460,2463 ---- *************** *** 2593,2597 **** B<add_error( @msg )> ! Adds message (C<join>ed C<msg>) to action parameter 'error_msg'). Returns: added message --- 2472,2476 ---- B<add_error( @msg )> ! Adds message (C<join>ed C<msg>) to parameter 'error_msg'). Returns: added message *************** *** 2599,2603 **** B<add_status( @msg )> ! Adds message (C<join>ed C<msg>) to action parameter 'status_msg'). Returns: added message --- 2478,2482 ---- B<add_status( @msg )> ! Adds message (C<join>ed C<msg>) to parameter 'status_msg'). Returns: added message |