From: Aaron Trevena Date: Mon, 12 Jun 2006 09:31:38 +0000 (+0000) Subject: added object method, not added to templates yet X-Git-Tag: 2.11~29 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=29550a30ca082a8f1f1d0cb1b4a92eb39bc3dd84;p=maypole.git added object method, not added to templates yet git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@491 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/Changes b/Changes index 2ca5c9a..53feab1 100644 --- a/Changes +++ b/Changes @@ -48,6 +48,7 @@ API additions and enhancements: - improved exception handling - now uses File::MMagic::XS to guess mime type of output unless already set - new component method provides Maypole::Component functionality + - new object method gets/sets first/only object in objects Maypole::Model - do_delete, do_search in place of delete/search actions Maypole::View::TT: diff --git a/META.yml b/META.yml index 1b7eda8..d0a0e42 100644 --- a/META.yml +++ b/META.yml @@ -1,7 +1,7 @@ # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Maypole -version: 2.11_pre3 +version: 2.11 version_from: lib/Maypole.pm installdirs: site requires: @@ -20,6 +20,7 @@ requires: Class::DBI::SQLite: 0 Digest::MD5: 0 File::MMagic::XS: 0.08 + HTML::Element: 0 HTTP::Body: 0.5 HTTP::Headers: 1.59 Template: 0 diff --git a/lib/Maypole.pm b/lib/Maypole.pm index d14f517..5837848 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -1146,6 +1146,24 @@ If the first item in C<$self-Eargs> can be Cd by the model class, it will be removed from C and the retrieved object will be added to the C list. See L for more information. + +=item object + +Alias to get/set the first/only model object. The object will be accessible +in the view templates. + +When used to set the object, will overwrite the request objects +with a single object. + +=cut + +sub object { + my ($r,$object) = @_; + $r->objects([$object]) if ($object); + return undef unless $r->objects(); + return $r->objects->[0]; +} + =item template_args $self->template_args->{foo} = 'bar'; @@ -1154,7 +1172,7 @@ Get/set a hash of template variables. =item stash -A place to put custom application data. Not used by Maypole itself. +A place to put custom application data. Not used by Maypole itself. =item template diff --git a/lib/Maypole/View/Base.pm b/lib/Maypole/View/Base.pm index 3164c01..1cc9b2b 100644 --- a/lib/Maypole/View/Base.pm +++ b/lib/Maypole/View/Base.pm @@ -41,7 +41,8 @@ sub vars { request => $r, objects => $r->objects, base => $base, - config => $r->config + config => $r->config, + object => $r->object, # ... ); diff --git a/lib/Maypole/View/TT.pm b/lib/Maypole/View/TT.pm index c399a6f..f634ca8 100644 --- a/lib/Maypole/View/TT.pm +++ b/lib/Maypole/View/TT.pm @@ -58,8 +58,8 @@ sub report_error { } if ($tt->process(\$error_template, { err_type => $type, error => $error, - config => { (%{$r->{config}}) }, - request => $r, # We have that at least + config => $r->{config}, + request => $r, eval{$self->vars($r)} }, \$output )) { $r->{output} = $output; if ($tt->error) { $r->{output} = "Even the error template @@ -399,19 +399,19 @@ the path "[% request.path %]". The error text returned was:

Request details

- - [% FOR thing = ["model_class", "table", "template", "path", +
+ [% FOR attribute = ["model_class", "table", "template", "path", "content_type", "document_encoding", "action", "args", "objects"] %] - + [% END %]
[%thing %] [% - request.$thing.list.join(" , ") %]
[% attribute %] [% + request.$attribute.list.join(" , ") %]

Application configuration

- - [% FOR thing = config.keys %] - +
[%thing %] [% - config.$thing.list.join(" , ") %]
+ [% FOR field IN config %] + [% END %]
[% field.key %] [% + $field.value.list.join(" , ") %]