Re: [Maypole] (no subject)

From: Simon Flack (sf at flacks.net)
Date: Fri Nov 19 2004 - 18:47:39 GMT


On Fri, 19 Nov 2004 18:23:33 +0000, Tony Bowden wrote
> On Fri, Nov 19, 2004 at 04:48:42PM +0000, Simon Flack wrote:
> > It would simplify things a lot, but would require turning the current
> > inheritance tree on its head.
>
> Whilst I don't want to speak to the specifics of
> Maypole::Application, which I haven't really investigated, I will
> however say that one of my concerns about Maypole is the current
> inheritance model - in particular the use of multiple inheritance,
> often by doing deep hackery to add something into something else's parents.
>
> Finding ways of teasing this apart, so that there's much more use of
> composition rather than inherance would IMO be a very positive step
> forward. I'd suggest looking more in that direction than in just reversing
> the direction of inheritance.

That's pretty much what I had in mind. I just don't know how big an impact it
is. How many apps inherit from Apache::MVC compared to Maypole::Application
for example.

Anyway, this is an example of what I had in mind:

    package Maypole;
    use strict;
    use vars '$AUTOOAD';
    # yada yada yada

    sub handler {
        my ($class, %arg) = @_;
        my $r = bless {}, $class;

        my $platform_name;
        if ($arg{platform}) {
            $platform_name = $arg{platform};
        } else {
            if ($ENV{MOD_PERL}) {
                $platform_name = 'Apache::MVC';
            } else {
                $platform_name = 'Maypole::CGI';
            }
        }
        $platform_name->require;
        $r->{_engine} = $platform_name->new();

        $r->process_request();
    }

    sub AUTOLOAD {
        my $r = shift;
        my ($method) = $AUTOLOAD =~ /.*:(.*)/;
        my %valid_dispatch = map {$_ => 1}
            qw(parse_location parse_args send_output get_template_root);

        croak "invalid method \$r->'$method'" unless $valid_dispatch{$method};
        $r->{_engine}->$method($r, @_);
    }

    # regular maypole methods continue

It's rough code to demonstrate. It may not even compile. But the idea is that
your apps would inherit from Maypole, and Maypole would invoke the necessary
methods on the modules that impliment the platform-specific guts.

It would mean we could remove Maypole::Application. And I believe it untangles
most of the multiple inheritance mess.

I'm quite keen to do this, and it shouldn't have a huge impact.

--simonflk

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT