On Sun, Jun 24, 2001 at 10:00:22PM -0700, Craig Barratt wrote:
> As one example, I added four lines of code to View.pm (see below)
> that allows me to implement the recursive Directory view example (see
> Template::Plugin::Directory) without using the present() method.

Nice!

> It's not that I have anything against the present method, I'm just
> lazy and I would like the view complex structures without additional
> perl code support and bless objects.

Yep, lazy is good!  In the cases of DOM/XPath, etc., it's possible
to define a general purpose present() method that's useful most of
the time (see other message in reply to Mark).  However, there are 
plenty of cases when you could do with something more specific and 
your suggestions seem like a good place to start.

I've applied the patch.  It's in 2.03b which will be out RSN...
Ooops - it broke t/view.t ... OK, I fixed it.  Needed to check
$item isa HASH before looking for $item->{ stuff }.  Here's the 
relevant part of the diffs for the change I made (against 2.03):

@@ -215,6 +215,8 @@
     
     # print each argument
     foreach $item (@_) {
+       my $newtype;
+
        if (! ($type = ref $item)) {
            # non-references are TEXT
            $type = 'TEXT';
@@ -232,8 +234,16 @@
                return unless defined $present;
                $output .= $present;
                next;                                   ## NEXT
+           }   
+           elsif ( UNIVERSAL::isa($item, 'HASH' ) 
+                  && defined($newtype = $item->{$method})
+                  && defined($template = $map->{"$method=>$newtype"})) {
            }
-           elsif (! ($template = $map->{ default })) {
+           elsif ( defined($newtype)
+                && defined($template = $map->{"$method=>*"}) ) {
+               $template =~ s/\*/$newtype/;
+            }    
+           elsif (! ($template = $map->{ default }) ) {
                # default not defined, so construct template name from type
                ($template = $type) =~ s/\W+/_/g;
            }

> My map syntax here isn't pretty, but perhaps a mechanism like this could
> be the basis of a more flexible map feature. 

Yep, I've left it undocumented for now and I'll have a think and see
if I can suggest anything.

Many thanks.
A


-- 
Andy Wardley <[EMAIL PROTECTED]>   Signature regenerating.  Please remain seated.
     <[EMAIL PROTECTED]>   For a good time: http://www.kfs.org/~abw/


Reply via email to