[Pangloss] [RFC] OpenFrame AppKit ideas
Jean-Michel Hiver
jhiver at mkdoc.com
Mon Apr 7 17:03:19 BST 2003
> + make SessionLoader segment abstract, then subclass for
> Cookies, URL's, and Form params.
URLs? How are you going to get the URLs to be automagically appended
with some kind of sessionIDs?
Plus, I think a session model based on the user name (when you do
authentication via HTTP authentication) would also be a good idea.
> I'm forced to invent a way of handling errors. I suppose I could
> just stick them in the Session and let the template writer deal
> with it. But then I gotta remove them on each request, and what
> if I want to handle them before they get to the template?
Actually I found a neat little trick for error handling.
You define an error class:
package My::Error;
$THROW_CODEREF = sub { die shift() };
# instanciates My::Object and invokes $THROW_CODEREF->($self)
sub new ($class);
# for the error to be easily embeddable
sub as_xhtml ($self);
Then you define an ErrorCatcher class:
package My::ErrorCatcher;
# adds an error to $error
sub _add_error ($error);
# returns a list of all errors
# or an array ref in scalar context
sub errors();
sub has_errors();
Then in your code you do something like:
use base qw /My::ErrorCatcher/;
sub do_something
{
my $self = shift;
# the current object is an ErrorCatcher, and at this point
# we don't want the errors to be fatal.
local $My::Error::THROW_CODEREF = sub {
my $error = shift;
$self->add_error ($error);
};
# the rest of the code goes here. If anything bad happened,
# $self->has_errors() should return TRUE and we just need to
# re-display the form and simply loop through the error array.
}
If you use Petal, you then can display all the errors quite simply as
follows:
<ul petal:condition="self/has_errors">
<li petal:repeat="error self/errors"
petal:content="structure error/as_xhtml">
An Evil Error has occurred!
</li>
</ul>
Then you just need to make as many subclasses as you have different
errors, since you can actually define more than one package in a module
it's not too bad.
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 Pangloss
mailing list