[Chicago-talk] design opinions
Steven Lembark
lembark at wrkhors.com
Thu Aug 12 19:24:37 CDT 2004
-- Jim Thomason <thomasoniii at gmail.com>
> http://www.jimandkoka.com/movie/edit.machine.txt
- Why quote the hash keys if you use => ?
'setup' => sub {
- If the states are sequential, why not use an array?
Shifting state handlers just means, say, shifting
the previous state off of a stack:
my @handlerz =
(
sub
{
# deal with startup
...
# done starting up
},
sub
{
# deal with running...
$cgi->install( blah ) => sub { ... };
$cgi->install( 'shutdown' ) => sub { return };
# sit around events via the table until the
# 'shutdown' event happens
while( more_events )
{
...
}
# exit when running is done
}
sub
{
# deal with exiting...
...
# exiting is done
},
);
# while there's something to handle...
#
# state handlers exit to signify the end of
# a state, last state => no more handlers.
while( my $handler = shift @handlerz )
{
$handler->();
}
That or have the handlers themselves shift @handlers to signify a
state change and change the loop to just:
$handlerz[0]->() while @handlerz;
Or put a sub { exit 0 } on the end and it becomes:
$handlerz[0]->();
The next-to-last state change does its shift leaving the exit
code on the stack.
Nice thing here is that EVERY::LAST (from Damian's NEXT module)
and some array inheritence allows for classes to push their
handlers onto a stack during initialization:
use base( handler1 handler2 ... );
my $stack = __PACKAGE__->construct;
$stack->[0]->() while $@stack;
Is all you really knead in the #! section.
I'll be sticking a module onto CPAN that does this in a
few weeks. Allows for things like:
my $thing = Bar->construct( my => values );
my $other = Bletch->construct( qw( new stack top ) );
package Foo;
use init
{
hashkey => value,
...
};
package Bar;
use base 'Foo';
use init
{
key => value,
};
package Bletch
use init
[
array
based
];
package Blort;
use base 'Bletch';
use init
[
top
of
stack
before
[
];
Main issues at this point are how to deal with mis-matched
data types in the inheritence stack. Warn me if it'd help
at all with your stuff.
--
Steven Lembark 9 Music Square South, Box 344
Workhorse Computing Nashville, TN 37203
lembark at wrkhors.com 1 888 359 3508
More information about the Chicago-talk
mailing list