From 02b642b7100a6e0a91e83aca3c4e63cd88786315 Mon Sep 17 00:00:00 2001 From: Aaron Trevena Date: Wed, 12 Apr 2006 13:37:38 +0000 Subject: [PATCH] ajt updates, fixed AsForm to pass pod and podcoverage tests, also removed usless use of constant in void context warnings by using parenthesis correctly git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@474 48953598-375a-da11-a14b-00016c27c3ee --- lib/Maypole/Model/CDBI/AsForm.pm | 49 +++++++++++++------------------- lib/Maypole/View/TT.pm | 11 +++++-- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/lib/Maypole/Model/CDBI/AsForm.pm b/lib/Maypole/Model/CDBI/AsForm.pm index 59bf438..66ccaf6 100644 --- a/lib/Maypole/Model/CDBI/AsForm.pm +++ b/lib/Maypole/Model/CDBI/AsForm.pm @@ -11,8 +11,6 @@ package Maypole::Model::CDBI::AsForm; # -- $class->to_field($has_many_col); # foreign inputs # $class->search_inputs; / -use 5.006; - use strict; use warnings; @@ -34,16 +32,8 @@ our @EXPORT = _options_from_objects _options_from_arrays _options_from_hashes _options_from_array _options_from_hash _to_select_or_create ); - -our @EXPORTOK = - qw( - - - ); - - -our $VERSION = '.10'; +our $VERSION = '.10'; =head1 NAME @@ -117,13 +107,15 @@ example usages. $beer->to_field($col, $args); Not all _to_* methods pay attention to all arguments. For example, '_to_textfield' does not look in $args->{'items'} at all. - + +=over + =item name -- the name the element will have , this trumps the derived name. $beer->to_field('brewery', 'readonly', { name => 'brewery_id' }); - + =item value -- the initial value the element will have, trumps derived value $beer->to_field('brewery', 'textfield', { @@ -199,12 +191,13 @@ static values. You can also specify these in the relationship arguments. constraint => {location => 'London'}, 'join' => {'brewery_tablecolumn => 'beer_obj_column'}, ); - + =item no_hidden_constraints -- Tell AsForm not to make hidden inputs for relationship constraints. It does this sometimes when making foreign inputs . +=back =head2 to_cgi @@ -362,6 +355,11 @@ sub search_inputs { } +=head2 unselect_element + + unselect any selected elemets in a HTML::Element select list widget + +=cut # sub unselect_element { @@ -462,7 +460,8 @@ sub _field_from_relationship { } return; } - + + =head2 _field_from_column($field, $args) Returns an input based on the column's characteristics, namely type, or nothing. @@ -1140,16 +1139,8 @@ sub _select_guts { } return $a; - - } - - - - - - =head2 _options_from_objects ( $objects, $args); Private method to makes a options out of objects. It attempts to call each @@ -1238,7 +1229,7 @@ sub _options_from_hashes { my $val = $_->{$pk}; my $opt = HTML::Element->new("option", value => $val ); $opt->attr(selected => "selected") if $selected->{$val}; - my $content = $fclass and $stringify and $fclass->can($stringify) ? + my $content = ($fclass and $stringify and $fclass->can($stringify)) ? $fclass->$stringify($_) : join(' ', @$_); $opt->push_content( $content ); @@ -1255,12 +1246,9 @@ sub _to_select_or_create { my $create = $self->to_field($col, 'foreign_inputs', $args); $create->{'__select_or_create__'} = $self->to_field('__select_or_create__',{ name => '__select_or_create__' , value => 1 } ); - return ($select, $create); } - - - + # # checkboxes: if no data in hand (ie called as class method), replace # with a radio button, in order to allow this field to be left @@ -1273,7 +1261,6 @@ sub _to_select_or_create { sub _to_checkbox { my ($self, $col, $args) = @_; my $nullable = eval {self->column_nullable($col)} || 0; - return $self->_to_radio($col) if !ref($self) || $nullable; my $value = $self->$col; my $a = HTML::Element->new("input", type=> "checkbox", name => $col); @@ -1358,7 +1345,8 @@ sub _rename_foreign_input { foreach (keys %$element); } } -=head2 _box($value) + +=head2 _box($value) This functions computes the dimensions of a textarea based on the value or the defaults. @@ -1366,6 +1354,7 @@ or the defaults. =cut our ($min_rows, $max_rows, $min_cols, $max_cols) = (2 => 50, 20 => 100); + sub _box { my $text = shift; diff --git a/lib/Maypole/View/TT.pm b/lib/Maypole/View/TT.pm index 5778d8b..c399a6f 100644 --- a/lib/Maypole/View/TT.pm +++ b/lib/Maypole/View/TT.pm @@ -51,10 +51,15 @@ sub report_error { my $output; # Need to be very careful here. my $tt = Template->new; + unless (ref $r->{config}) { + warn "no config for this request\n"; + $error .= '
There was a problem finding configuration for this request'; + $r->{config} ||= {}; + } if ($tt->process(\$error_template, - { err_type => $type, error => $error, - config => { %{$r->{config}}}, - request => $r, # We have that at least + { err_type => $type, error => $error, + config => { (%{$r->{config}}) }, + request => $r, # We have that at least eval{$self->vars($r)} }, \$output )) { $r->{output} = $output; if ($tt->error) { $r->{output} = "Even the error template -- 2.39.2