Skip Menu |

This queue is for tickets about the Maypole CPAN distribution.

Report information
The Basics
Id: 12383
Status: resolved
Priority: 0/
Queue: Maypole

People
Owner: Nobody in particular
Requestors: dave [...] riverside-cms.co.uk
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.09
Fixed in: 2.10



Subject: MP::Application doesn't work with MasonX::Maypole [patch]
I sent an ugly hack to simon a while ago, but it was pretty poor. This patch is better, so you can just say use Maypole::Application qw( -MasonX ); The format is diff -u --- /usr/local/lib/perl5/site_perl/5.8.6/Maypole/Application.pm Tue Jan 25 21:53:08 2005 +++ /home/dave/distributions/Maypole-Application/lib/Maypole/Application.pm Sat Apr 23 01:03:33 2005 @@ -13,6 +13,23 @@ my ( $class, @plugins ) = @_; my $caller = caller(0); + my ( $frontend, $masonx ); + + $frontend = 'Apache::MVC' if $ENV{MOD_PERL}; + + if ( grep { /^\-MasonX$/ } @plugins ) + { + $masonx++; + @plugins = grep { ! /^\-MasonX$/ } @plugins; + $frontend = 'MasonX::Maypole'; + } + + $frontend ||= 'CGI::Maypole'; + + # should die here, not warn, but die is silent for some reason + $frontend->require or warn "Loading $frontend frontend failed: $@"; + push @ISA, $frontend; + my $autosetup=0; my @plugin_modules; { @@ -40,16 +57,8 @@ no strict 'refs'; push @{"${caller}::ISA"}, @plugin_modules, $class; $caller->config(Maypole::Config->new); + $caller->config->masonx({}) if $masonx; $caller->setup() if $autosetup; -} - -if ( $ENV{MOD_PERL} ) { - Apache::MVC->require or die "Loading Apache frontend failed: $@"; - push @ISA, 'Apache::MVC'; -} -else { - CGI::Maypole->require or die "Loading CGI frontend failed: $@"; - push @ISA, 'CGI::Maypole'; } 1;
[DAVEBAIRD - Fri Apr 22 20:35:46 2005]: Just realised the regex probably shouldn't match -MasonX, but should match MasonX, as it's more like a plugin than a switch. d. Show quoted text
> I sent an ugly hack to simon a while ago, but it was pretty poor. This > patch is better, so you can just say > > use Maypole::Application qw( -MasonX ); > > The format is diff -u > > --- /usr/local/lib/perl5/site_perl/5.8.6/Maypole/Application.pm Tue > Jan 25 21:53:08 2005 > +++ /home/dave/distributions/Maypole- > Application/lib/Maypole/Application.pm Sat Apr 23 01:03:33 2005 > @@ -13,6 +13,23 @@ > my ( $class, @plugins ) = @_; > my $caller = caller(0); > > + my ( $frontend, $masonx ); > + > + $frontend = 'Apache::MVC' if $ENV{MOD_PERL}; > + > + if ( grep { /^\-MasonX$/ } @plugins ) > + { > + $masonx++; > + @plugins = grep { ! /^\-MasonX$/ } @plugins; > + $frontend = 'MasonX::Maypole'; > + } > + > + $frontend ||= 'CGI::Maypole'; > + > + # should die here, not warn, but die is silent for some reason > + $frontend->require or warn "Loading $frontend frontend failed: > $@"; > + push @ISA, $frontend; > + > my $autosetup=0; > my @plugin_modules; > { > @@ -40,16 +57,8 @@ > no strict 'refs'; > push @{"${caller}::ISA"}, @plugin_modules, $class; > $caller->config(Maypole::Config->new); > + $caller->config->masonx({}) if $masonx; > $caller->setup() if $autosetup; > -} > - > -if ( $ENV{MOD_PERL} ) { > - Apache::MVC->require or die "Loading Apache frontend failed: $@"; > - push @ISA, 'Apache::MVC'; > -} > -else { > - CGI::Maypole->require or die "Loading CGI frontend failed: $@"; > - push @ISA, 'CGI::Maypole'; > } > > 1;
Me again. The comment in the last patch about die not working turns out to be a bug somewhere in my own app, not Maypole. So here's another patch. This also has a couple of things I find useful. Warnings mention the class of the caller, which is useful if you run multiple Maypole apps. Failed plugin loads die instead of warn. And multiple debug levels are supported, useful for instance in Maypole::Plugin::AutoUntaint. Regards, d. --- /usr/local/lib/perl5/site_perl/5.8.6/Maypole/Application.pm Tue Jan 25 21:53:08 2005 +++ /home/dave/distributions/Maypole-Application/lib/Maypole/Application.pm Thu Apr 28 09:45:40 2005 @@ -12,26 +12,42 @@ sub import { my ( $class, @plugins ) = @_; my $caller = caller(0); + + my $frontend = 'Apache::MVC' if $ENV{MOD_PERL}; + + my $masonx; + if ( grep { /^MasonX$/ } @plugins ) + { + $masonx++; + @plugins = grep { ! /^MasonX$/ } @plugins; + $frontend = 'MasonX::Maypole'; + } + + $frontend ||= 'CGI::Maypole'; + + $frontend->require or die "Loading $frontend frontend failed: $@"; + push @ISA, $frontend; my $autosetup=0; my @plugin_modules; { foreach (@plugins) { if (/^\-Setup$/) { $autosetup++; } - elsif (/^\-Debug$/) { + elsif (/^\-Debug(\d*)$/) { + my $d = $1 || 1; no strict 'refs'; - *{"$caller\::debug"} = sub { 1 }; - warn "Debugging enabled"; + *{"$caller\::debug"} = sub { $d }; + warn "Debugging (level $d) enabled for $caller"; } elsif (/^-.*$/) { warn "Unknown flag: $_" } else { my $plugin = "Maypole::Plugin::$_"; if ($plugin->require) { push @plugin_modules, "Maypole::Plugin::$_"; - warn "Loaded plugin: $plugin" + warn "Loaded plugin: $plugin for $caller" if $caller->can('debug') && $caller->debug; } else { - warn qq(Loading plugin "$plugin" failed: ) + die qq(Loading plugin "$plugin" for $caller failed: ) . $UNIVERSAL::require::ERROR; } } @@ -40,18 +56,10 @@ no strict 'refs'; push @{"${caller}::ISA"}, @plugin_modules, $class; $caller->config(Maypole::Config->new); + $caller->config->masonx({}) if $masonx; $caller->setup() if $autosetup; } -if ( $ENV{MOD_PERL} ) { - Apache::MVC->require or die "Loading Apache frontend failed: $@"; - push @ISA, 'Apache::MVC'; -} -else { - CGI::Maypole->require or die "Loading CGI frontend failed: $@"; - push @ISA, 'CGI::Maypole'; -} - 1; =head1 NAME @@ -68,9 +76,11 @@ use Maypole::Application qw(Config::YAML Loader -Setup -Debug); + use Maypole::Application qw(-Debug2 MasonX AutoUntaint); + =head1 DESCRIPTION -This is a universal frontend for mod_perl1, mod_perl2 and CGI. +This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI. You can omit the Maypole::Plugin:: prefix from plugins. So Maypole::Plugin::Config::YAML becomes Config::YAML. @@ -105,6 +115,8 @@ use Maypole::Application; sub debug { 1 } + +You can specify a higher debug level by saying C<-Debug2> etc. =head1 AUTHOR
From: TeeJay
[guest - Thu Apr 28 05:00:15 2005]: Show quoted text
> Me again. The comment in the last patch about die not working turns > out > to be a bug somewhere in my own app, not Maypole. So here's another > patch. This also has a couple of things I find useful. Warnings > mention > the class of the caller, which is useful if you run multiple Maypole > apps. Failed plugin loads die instead of warn. And multiple debug > levels > are supported, useful for instance in Maypole::Plugin::AutoUntaint.
Patch applied to SVN, now in revision 340 A