[Petal] Accessor methods in path statements? - Comments please!
Kurt Stephens
kstep@pepsdesign.com
Fri, 6 Sep 2002 20:25:44 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_000B_01C255E3.93E34F00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Greetings, All!
After spending some time examining the internals of VAR.pm, I began to play
around with the idea of allowing a single method argument to be declared
directly in the path statement. While this may seem rather upsetting at
first, this is based on the following logic:
Why should the argument to an accessor method be treated any differently
than a hash key or an array index?
For example, imagine an application framework where the template is
populated with a single application object.
$template->process($app);
In a contrived case, I could specify the path
<? petal:var name="app/forms/userinfo/fields/username/value" ?>
which maps to the method call:
$app->forms('userinfo')->fields('username')->value().
Attached is an EXPERIMENTAL hacked version of VAR.pm, named XVAR.pm, that
implements this behavior. I also included a demonstration of this in
xvar_pathdemo.pl. The XVAR module also implements a bizarre feature of
_questionable_virtue_ that replaces the argument token pulled from the path
if there is any indication that it may be a valid key, index or method for
the value returned by the last call. The upside to this is that it allows
calls to methods with no parameters that return object, array or hash
references. The downside is demonstrated in the file xvar_pathology.pl,
where I demonstrate how this algorithm will become confused and do the wrong
thing when the accessor argument is the same as a method name.
Aside from this, the XVAR module has a few features that I think belong in
the production version of VAR.pm. I have wrapped the method calls in eval{}
blocks, and changed the handling of autoloaded methods so that if AUTOLOAD
fails with an 'Undefined subroutine' value in $@, the $next argument will
still be tested as a possible hash key or array index.
Again, I stress that XVAR.pm is an experimental module that demonstrates
alternate path semantics and possible improvements to the object handling
code in VAR.pm. It is intended for educational and entertainment purposes
only!
Any comments would be most welcome.
Best Regards,
Kurt Stephens
kstep@pepsdesign.com
------=_NextPart_000_000B_01C255E3.93E34F00
Content-Type: application/x-gzip;
name="xvar.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="xvar.tar.gz"
H4sICBE4eT0AC3h2YXIudGFyAO0ba1PbSHI/pyr/YQJsZF/ANmZD6iC8QtiDy4MtILe3h1lqLI9t
LbLkSHK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