From 2c5d6782f89dc1532398b1b79c8f67b982c758ac Mon Sep 17 00:00:00 2001 From: Aaron Trevena Date: Thu, 30 Nov 2006 16:07:44 +0000 Subject: [PATCH] fixed bug 22899 + broken link in manual contents, removed some warnings, fixed DFV test, fixed and added global populate cgi attribute and usage git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@552 48953598-375a-da11-a14b-00016c27c3ee --- Changes | 2 +- lib/Apache/MVC.pm | 18 +++++ lib/Maypole.pm | 134 ++++++++++++++++++------------------ lib/Maypole/Config.pm | 11 ++- lib/Maypole/Manual.pod | 2 +- lib/Maypole/Manual/Flox.pod | 2 +- t/00compile.t | 2 +- 7 files changed, 98 insertions(+), 73 deletions(-) diff --git a/Changes b/Changes index e5f081c..276835e 100644 --- a/Changes +++ b/Changes @@ -14,7 +14,7 @@ For information about current developments and future releases, see: New config method : additional, for stashing additional info, especially from additional_data method new warn method in maypole/request class/object, over-ridden by Apache::MVC, etc or own driver AsForm fixes to stringification _to_select - new build_form_elements attribute for Maypole request, set it to 0 to avoid building cgi form if you don't need it + new build_form_elements attribute for Maypole request and Maypole::Config, set it to 0 to avoid building cgi form if you don't need it made DFV and FromCGI warn instead of die on unexpected cgi params added CGI params to TT error template small improvements to some factory templates diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index d5909bf..8315276 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -163,6 +163,24 @@ sub parse_args { =item redirect_request +Sets output headers to redirect based on the arguments provided + +Accepts either a single argument of the full url to redirect to, or a hash of +named parameters : + +$r->redirect_request('http://www.example.com/path'); + +or + +$r->redirect_request(protocol=>'https', domain=>'www.example.com', path=>'/path/file?arguments', status=>'302', url=>'..'); + +The named parameters are protocol, domain, path, status and url + +Only 1 named parameter is required but other than url, they can be combined as +required and current values (from the request) will be used in place of any +missing arguments. The url argument must be a full url including protocol and +can only be combined with status. + =cut sub redirect_request diff --git a/lib/Maypole.pm b/lib/Maypole.pm index 858437e..bc41335 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -467,12 +467,12 @@ to the method sub component { my ( $r, $path ) = @_; my $self = bless { parent => $r, config => $r->{config}, } , ref $r; - $self->stash({}); - $self->params({}); - $self->query({}); - $self->template_args({}); - $self->args([]); - $self->objects([]); + $self->stash({}); + $self->params({}); + $self->query({}); + $self->template_args({}); + $self->args([]); + $self->objects([]); $self->get_user; my $url = URI->new($path); @@ -538,66 +538,59 @@ request/response and defines the workflow within Maypole. =cut # The root of all evil -sub handler_guts -{ - my ($self) = @_; - $self->build_form_elements(1); - $self->__load_request_model; +sub handler_guts { + my ($self) = @_; + $self->build_form_elements(1) unless (defined ($self->config->build_form_elements) && $self->config->build_form_elements == 0); + $self->__load_request_model; - my $applicable = $self->is_model_applicable == OK; + my $applicable = $self->is_model_applicable == OK; - my $status; + my $status; - # handle authentication - eval { $status = $self->call_authenticate }; - if ( my $error = $@ ) - { - $status = $self->call_exception($error, "authentication"); - if ( $status != OK ) - { - warn "caught authenticate error: $error"; - return $self->debug ? - $self->view_object->error($self, $error) : ERROR; - } - } - if ( $self->debug and $status != OK and $status != DECLINED ) - { - $self->view_object->error( $self, - "Got unexpected status $status from calling authentication" ); + # handle authentication + eval { $status = $self->call_authenticate }; + if ( my $error = $@ ) { + $status = $self->call_exception($error, "authentication"); + if ( $status != OK ) { + $self->warn("caught authenticate error: $error"); + return $self->debug ? + $self->view_object->error($self, $error) : ERROR; } + } + if ( $self->debug and $status != OK and $status != DECLINED ) { + $self->view_object->error( $self, + "Got unexpected status $status from calling authentication" ); + } - return $status unless $status == OK; - - # We run additional_data for every request - $self->additional_data; + return $status unless $status == OK; - if ($applicable) { - eval { $self->model_class->process($self) }; - if ( my $error = $@ ) - { - $status = $self->call_exception($error, "model"); - if ( $status != OK ) - { - warn "caught model error: $error"; - return $self->debug ? - $self->view_object->error($self, $error) : ERROR; - } - } - } else { - $self->__setup_plain_template; + # We run additional_data for every request + $self->additional_data; + + if ($applicable) { + eval { $self->model_class->process($self) }; + if ( my $error = $@ ) { + $status = $self->call_exception($error, "model"); + if ( $status != OK ) { + $self->warn("caught model error: $error"); + return $self->debug ? + $self->view_object->error($self, $error) : ERROR; + } } + } else { + $self->__setup_plain_template; + } - # less frequent path - perhaps output has been set to an error message - return OK if $self->output; - - # normal path - no output has been generated yet - my $processed_view_ok = $self->__call_process_view; + # less frequent path - perhaps output has been set to an error message + return OK if $self->output; - $self->{content_type} ||= $self->__get_mime_type(); - $self->{document_encoding} ||= "utf-8"; + # normal path - no output has been generated yet + my $processed_view_ok = $self->__call_process_view; + $self->{content_type} ||= $self->__get_mime_type(); + $self->{document_encoding} ||= "utf-8"; - return $processed_view_ok; + return $processed_view_ok; } my %filetypes = ( @@ -629,8 +622,8 @@ sub __load_request_model if ( eval {$mclass->isa('Maypole::Model::Base')} ) { $self->model_class( $mclass ); } - elsif ($self->debug) { - warn "***Warning: No $mclass class appropriate for model. @_"; + elsif ($self->debug > 1) { + $self->warn("***Warning: No $mclass class appropriate for model. @_"); } } @@ -644,11 +637,13 @@ sub __setup_plain_template # It's just a plain template $self->model_class(undef); - + + # FIXME: this is likely to be redundant and is definately causing problems. + my $path = $self->path; $path =~ s{/$}{}; # De-absolutify $self->path($path); - + $self->template($self->path); } @@ -692,8 +687,11 @@ sub warn { } $r->build_form_elements(0); -Specify whether to build HTML form elements and populate -the cgi element of classmetadata. +Specify (in an action) whether to build HTML form elements and populate +the cgi element of classmetadata in the view. + +You can set this globally using the accessor of the same name in Maypole::Config, +this method allows you to over-ride that setting per action. =cut @@ -1335,13 +1333,13 @@ sub redirect_request { die "redirect_request is a virtual method. Do not use Maypole directly; use Apache::MVC or similar"; } -=item redirect_internal_request - -=cut - -sub redirect_internal_request { - -} +# =item redirect_internal_request +# +# =cut +# +# sub redirect_internal_request { +# +# } =item make_random_id diff --git a/lib/Maypole/Config.pm b/lib/Maypole/Config.pm index 2cf65da..3307f8f 100644 --- a/lib/Maypole/Config.pm +++ b/lib/Maypole/Config.pm @@ -11,7 +11,7 @@ our $VERSION = "1." . sprintf "%04d", q$Rev$ =~ /: (\d+)/; __PACKAGE__->mk_accessors( qw( view view_options uri_base template_root template_extension model loader display_tables ok_tables rows_per_page dsn user pass opts - application_name additional) + application_name additional build_form_elements) ); # Should only be modified by model. @@ -65,6 +65,15 @@ makes URLs. The name of the view class for your Maypole Application. Defaults to "Maypole::View::TT". +=head3 build_form_elements + +Globally specify whether to build form elements; populating the cgi metadata with +autogenerated HTML::Element widgets for the class/object. + +Can be over-ridden per action using the method of the same name for the request. + +If not set, then Maypole will assume it is true. + =head3 view_options A hash of configuration options for the view class. Consult the documentation diff --git a/lib/Maypole/Manual.pod b/lib/Maypole/Manual.pod index d556ae9..d2f4ed6 100644 --- a/lib/Maypole/Manual.pod +++ b/lib/Maypole/Manual.pod @@ -107,7 +107,7 @@ Orkut. It shows, specifically, the database structure and the variety of customized techniques that make such a system work. -=item L - Case Study: iBuySpy * +=item L - Case Study: iBuySpy * This is an example of the C sample portal application ported to Maypole. L is a fictional diff --git a/lib/Maypole/Manual/Flox.pod b/lib/Maypole/Manual/Flox.pod index ed3309c..df3cff8 100644 --- a/lib/Maypole/Manual/Flox.pod +++ b/lib/Maypole/Manual/Flox.pod @@ -505,5 +505,5 @@ L. L, Next L, -Previous L +Previous L diff --git a/t/00compile.t b/t/00compile.t index 8c64ce4..c040443 100644 --- a/t/00compile.t +++ b/t/00compile.t @@ -17,7 +17,7 @@ use_ok('Maypole::Model::CDBI::FromCGI'); use_ok('Maypole::Model::CDBI::AsForm'); SKIP: { - eval { use Data::FormValidator }; + eval { require Data::FormValidator; }; skip 'Data::FormValidator is not installed or does not work', 1 if ($@); use_ok('Maypole::Model::CDBI::DFV'); } -- 2.39.5