[Petal] [PATCH] Options via constructor rather than package
globals
Jean-Michel Hiver
jhiver at mkdoc.com
Thu Jun 5 12:01:45 BST 2003
> 1. a base class for all Petal objects, ie: Petal::Object, or
> Petal::Base. To begin with, this would contain new() and
> _initialize(), which are easily overrided.
I'm not sure if I agree with the concept of 'base classes'. I mean,
there is one, called UNIVERSAL. It has a few methods like can() and
isa() but it features no constructors.
Until there is a popular CPAN 'base class' that does anything you'd want
in a base class (constructors, initialization, popular methods...) then
I'd prefer to stick with implementing a constructor each time.
Maybe Petal objects should inherit from Class::Base?
> 2. cascade-able accessor methods which let you do:
>
> $template
> ->language('fr')
> ->input('HTML')
> ->output('XHTML');
Now I find this really, really useless :)
I disagree with the idea of constructing an object that is in an
inconsistent state and setting the state afterwards through some strange
syntaxic sugar.
I suppose it doesn't cost much to implement... since you don't have to
use it if you don't want it, it's probably a good idea despite the fact
that I don't like it :)
> 3. use accessors within _initialize(). In the off-chance that
> someone comes along and sub-classes Petal :)
>
> Additionally, you might get rid of a lot of cut-n-paste work in
> _initialize() by doing something like:
>
> ...
> foreach my $param (qw( taint disk_cache ... )) {
> no strict 'refs';
> my $val = exists $o{$param}
> ? $o{param}
> : ${'Petal::' . uc(param)
> $self->$param( $val );
> }
That's probably a good idea.
> Again, good work. Lets hope Jean-Michel agrees ;-)
I applied the patch, looked at it, and then tweaked a little bit things
the way I wanted...
Having the options at an object level did really involve quite a lot of
changes. So instead of making the rest of Petal code aware of per-object
options, I changed the process() method to declare the global options
variables as local and set them to the per-objects options.
It might seem like a bit of a hack but I think it's acceptable and it
fits in better with the way Petal was designed to start with. Also, the
patch seemed to fail one test...
Anyway since I haven't released Petal in a while I'll to a .93 release
that should sort out the most urgent stuff (including the
Petal::Hash::VAR bug you pointed out). Meanwhile more deep changes to
Petal will have to wait...
Cheers,
--
Building a better web - http://www.mkdoc.com/
---------------------------------------------
Jean-Michel Hiver
jhiver at mkdoc.com - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/
More information about the Petal
mailing list