Posted on 2005-02-09 00:59:27-08 by mreece
getting started (cont)
so i realized i needed to set the PerlHandler (duh)
<Location /beerdb/> SetHandler perl-script PerlHandler BeerDB </Location>
(also changed all paths to beerdb for consistency, i think this may matter) however, i now get an error:
[Tue Feb 8 16:53:24 2005] [error] Can't use an undefined value as a HASH reference at /usr/local/a +pache_perl/packages/BeerDB.pm line 18. Compilation failed in require at (eval 235) line 3. [Tue Feb 8 16:53:24 2005] [error] Can't use an undefined value as a HASH reference at /usr/lib/per +l5/site_perl/5.6.1/MasonX/Maypole.pm line 160.
line 18 of BeerDB.pm is
BeerDB->config->masonx->{comp_root} = [ factory => '/usr/lib/perl5/site_perl/5.6.1/templates/factory/maypole' ];
and line 160 of Maypole.pm is
my $comp_roots = $class->config->masonx->{comp_root} || [];
am i missing a step? why is masonx undefined at this point?
Direct Responses: 73 | Write a response
Posted on 2005-02-09 11:40:10-08 by davebaird in response to 71
Re: getting started (cont)

The template root is the home of your application. So if the whole application is being handled by Maypole, then the template_root is the same as the document root. But if the Maypole application lives within a subdirectory of the website, then the template_root is the full path to that subdirectory. In your case, it'd be $DOCUMENT_ROOT/beerdb

The factory root is where Maypole looks if it doesn't find a template in the template_root, or a table-specific subdirectory. These are the templates that are provided in the distribution. I don't think they get installed anywhere during installation. You have to go into the build directory (somewhere in the .cpan directory) and fish them out and install them somewhere, say /usr/local/www/maypole. Or pull them out of the .tar.gz distribution file.

These undefined value errors look like you haven't inherited from MasonX::Maypole. Your BeerDB.pm needs to look a bit like this:

package BeerDB.pm; use strict; use warnings; use base 'MasonX::Maypole'; BeerDB->setup( ...db params... ); # then the various BeerDB->config calls as in the MasonX::Maypole synopsis, including BeerDB->config->{template_root} = "$DOCUMENT_ROOT/beerdb"; BeerDB->config->{uri_base} = '/beerdb'; BeerDB->config->masonx->{comp_root} = [ factory => '/usr/local/www/maypole' ]; # etc.

Now you can drop your own templates into $DOCUMENT_ROOT/beerdb, and they'll override those in /usr/local/www/maypole. And you can drop table-specific templates in $DOCUMENT_ROOT/beerdb/$table_moniker, and they'll override those in $DOCUMENT_ROOT/beerdb

d.

Direct Responses: 83 | Write a response
Posted on 2005-02-10 18:05:33-08 by mreece in response to 73
Re: getting started (cont)
my BeerDB.pm looks like this:
package BeerDB; use warnings; use strict; use Class::DBI::Loader::Relationship; use MasonX::Maypole 0.2; use base 'MasonX::Maypole'; BeerDB->setup( 'dbi:mysql:beerdb:localhost:mysql_socket=/var/lib/mysql/mysql.sock', *deleted*, *del +eted* ); BeerDB->config->{view} = 'MasonX::Maypole::View'; BeerDB->config->{template_root} = '/Public/mason/beerdb'; BeerDB->config->{uri_base} = '/beerdb'; BeerDB->config->{rows_per_page} = 10; BeerDB->config->{display_tables} = [ qw( beer brewery pub style ) ]; BeerDB->config->masonx->{comp_root} = [ factory => '/Public/maypole' ]; BeerDB->config->masonx->{data_dir} = '/usr/local/apache_perl/mason'; BeerDB->config->masonx->{in_package} = 'My::Mason::App'; BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] ); BeerDB::Style->untaint_columns( printable => [qw/name notes/] ); BeerDB::Beer->untaint_columns( printable => [qw/abv name price notes/], integer => [qw/style brewery score/], date => [ qw/date/], ); BeerDB->config->{loader}->relationship($_) for ( "a brewery produces beers", "a style defines beers", "a pub has beers on handpumps"); 1;
and i am still getting:
[Thu Feb 10 09:58:00 2005] [error] Can't use an undefined value as a HASH reference at /usr/local/a +pache_perl/packages/BeerDB.pm line 20. Compilation failed in require at (eval 445) line 3. [Thu Feb 10 09:58:00 2005] [error] Can't use an undefined value as a HASH reference at /usr/lib/per +l5/site_perl/5.6.1/MasonX/Maypole.pm line 160.
it is using the right Maypole.pm, and i see the line
Maypole::Config->mk_accessors( 'masonx' );
in there, so it is odd that line 160
my $comp_roots = $class->config->masonx->{comp_root} || [];
is giving an undefined HASH ref error..
Direct Responses: 84 | Write a response
Posted on 2005-02-10 18:47:25-08 by mreece in response to 83
Re: getting started (cont)
BeerDB->config has the accessor ->masonx, but it is returning undef. if i do
BeerDB->config->masonx({});
before the
BeerDB->config->masonx->{comp_root} = [ factory => '/Public/maypole' ];
then it gets past the previous errors, but i get
[Thu Feb 10 10:44:09 2005] [error] Can't locate object method "untaint_columns" via package "BeerDB +::Style" (perhaps you forgot to load "BeerDB::Style"?) at /usr/local/apache_perl/packages/BeerDB.p +m line 28. Compilation failed in require at (eval 685) line 3. [Thu Feb 10 10:44:09 2005] [error] Can't use string ("factory") as an ARRAY ref while "strict refs" + in use at /usr/lib/perl5/site_perl/5.6.1/MasonX/Maypole.pm line 166.
Direct Responses: 85 | Write a response
Posted on 2005-02-10 19:13:02-08 by mreece in response to 84
Re: getting started (cont)
commenting out the BeerDB::Style->untaint_columns

and changing the comp_root like to
BeerDB->config->masonx->{comp_root} = [ [ factory => '/Public/maypole' ] ];
gets past that error, but i am wandering so far from the sample package that i fear some underlying thing is still broken or misconfigured.

curiously, only BeerDB::Brewery->untaint_columns works, as though the class loader is not creating classes for BeerDB::Style or BeerDB::Beer. if i comment out the untaint_columns calls for those classes, i get a warning about "Couldn't understand the second object you were talking about at" in the relationships($_) loop, and ultimately get a " A poorly configured Maypole application" page showing "List by beer", "List by brewery", etc, but all of those lead to errors
error: could not find component for path 'beerdb/beer/list' context: 1: <& $request->template, %ARGS &> 2: code stack: /Public/maypole/dhandler:1 /usr/lib/perl5/site_perl/5.6.1/HTML/Mason/Component.pm:136 /Public/maypole/autohandler:4 /usr/lib/perl5/site_perl/5.6.1/HTML/Mason/Component.pm:136
Direct Responses: 86 | Write a response
Posted on 2005-02-10 21:20:54-08 by davebaird in response to 85
Re: getting started (cont)

Hmm. OK, you're right, there is a typo in the synopsis, and the comp_root call should be a nested arrayref:

BeerDB->config->masonx->{comp_root} = [ [ factory => '/Public/maypole' ] ];

Sorry about that. For the rest though, I'm still wondering if the paths are set up correctly. What is DocumentRoot set to in the Apache config? I'll go back and set up the BeerDB app here and see if it still works, my own app is a bit removed from that setup now.

Direct Responses: 88 | 89 | Write a response
Posted on 2005-02-10 23:49:09-08 by davebaird in response to 86
Re: getting started (cont)

Yep, the uninitialized masonx was a bug. I've just uploaded a new version (0.216) to CPAN. I've added a full BeerDB.pm example package (with real paths on a real server) and a corresponding VirtualHost Apache config. These are in the /doc directory of the distribution. Let me know if this helps.

d.

Direct Responses: Write a response
Posted on 2005-02-10 23:58:20-08 by mreece in response to 86
Re: getting started (cont)
The DocumentRoot is actually outside of Mason's control. Document root is /Public/apache, but Mason apps live under /Public/mason and are configured with blocks such as:

PerlSetVar MasonCompRoot /Public/mason Alias /beerdb/ /Public/mason/beerdb/ <Location /beerdb/> SetHandler perl-script PerlHandler BeerDB # other Locations use PerlHandler HTML::Mason::ApacheHandler </Location>

could that be a problem for MasonX::Maypole?

I have tried putting the factory templates in both /Public/apache/maypole and /Public/mason/maypole and adjusting the comp_root [ [ factory=> ... ] ] accordingly, but in both instances i get:
...
could not find component for path 'beerdb/beer/list' Trace begun at /usr/lib/perl5/site_perl/5.6.1/HTML/Mason/Request.pm line 996 HTML::Mason::Request::comp('MasonX::Request::ExtendedCompRoot=HASH(0x85d97ec)', 'beerdb/beer/list') + called at /Public/apache/maypole/dhandler line 1 BeerDB::__ANON__ at /usr/lib/perl5/site_perl/5.6.1/HTML/Mason/Component.pm line 136
(or called at /Public/mason/maypole/dhandler, in the other case)
Direct Responses: 90 | Write a response
Posted on 2005-02-11 00:36:56-08 by davebaird in response to 89
Re: getting started (cont)

OK. Don't set MasonCompRoot for a MasonX::Maypole app. MX::MP takes care of that. It sets the 'main' comp root to the template_root config setting. Your settings for this look OK:

BeerDB->config->{template_root} = '/Public/mason/beerdb'; BeerDB->config->{uri_base} = '/beerdb';

There may be a gotcha with the factory root. In the distribution, you get

lib/templates/factory lib/templates/beerd

You need to copy the contents of lib/templates/factory to /Public/apache/maypole. In other words, the factory comp_root needs to point to the factory subdir of the supplied templates. Don't bother with the beerdb subdir by the way - it's just a single comp that I haven't ported from TT.

d.

Direct Responses: 93 | Write a response
Posted on 2005-02-11 17:52:02-08 by mreece in response to 90
Re: getting started (cont)
it is finding the factory root because it runs that autohandler and dhandler and shows the <& frontpage &> comp. on subsequent urls, such as /beerdb/beer/list, it again finds the factory components and uses that dhandler. it then fails on
<& $request->template, %ARGS &>
with the error "could not find component for path 'beerdb/beer/list'"

The MasonCompRoot is set outside of the <Location> blocks, so I cannot simply not set it, as all the other Mason apps need it. Is there a way to unset it inside the <Location> block?
Direct Responses: 94 | 115 | Write a response
Posted on 2005-02-11 18:15:14-08 by mreece in response to 93
Re: getting started (cont)
i get other errors in the apache error log, such as
Loaded tables: beer at /usr/lib/perl5/site_perl/5.6.1/Maypole/Model/CDBI.pm line 244. [Fri Feb 11 10:07:33 2005] [error] Can't locate object method "untaint_columns" via package "BeerDB +::Brewery" (perhaps you forgot to load "BeerDB::Brewery"?) at /usr/local/apache_perl/packages/Beer +DB.pm line 23. Compilation failed in require at (eval 356) line 3. We don't have that table (frontpage). Available tables are: beer,brewery,pub,style at /usr/lib/perl5/site_perl/5.6.1/Maypole.pm line 144. Subroutine debug redefined at /usr/local/apache_perl/packages/BeerDB.pm line 41. Loaded tables: beer at /usr/lib/perl5/site_perl/5.6.1/Maypole/Model/CDBI.pm line 244. We don't have that table (beerdb). Available tables are: beer,brewery,pub,style at /usr/lib/perl5/site_perl/5.6.1/Maypole.pm line 144.
so i wonder if something is up with the class loader, though i have v0.14 installed.. or perhaps my setup string is incorrect.. though it appears correct
BeerDB->setup( 'dbi:mysql:beerdb:localhost:mysql_socket=/var/lib/mysql/mysql.sock', 'username', 'pa +ssword' );
the loader works for BeerDB::Beer->untaint_columns, but not for BeerDB::Style and BeerDB::Brewery though those tables do exist:
mysql> use beerdb ; Database changed mysql> show tables ; +------------------+ | Tables_in_beerdb | +------------------+ | beer | | brewery | | handpump | | pub | | style | +------------------+
Direct Responses: 113 | Write a response
Posted on 2005-02-14 20:36:59-08 by mreece in response to 94
Re: getting started (cont)
so i was able to fix the Loader problems by upgradeing DBD::mysql. that gets rid of all warnings and errors in the apache log, but i still get
error: could not find component for path 'beerdb/beer/list' context: 1: <& $request->template, %ARGS &> 2: code stack: /Public/mason/maypole/factory/dhandler:1 /usr/lib/perl5/site_perl/5.6.1/HTML/Mason/Component.pm:136 /Public/mason/maypole/factory/autohandler:4
if i try to click any of the URLs generated by the frontpage component. as you can see from the paths, it is finding the factory and using the appropriate autohandler and dhandler, but fails to 'find' the component for /beerdb/beer/list.
Direct Responses: 114 | Write a response
Posted on 2005-02-15 00:23:54-08 by davebaird in response to 113
Re: getting started (cont)

I'd noticed these warnings myself, but hadn't tracked them down yet. They're coming from somewhere deep in the Maypole/CDBI hierarchy, I'll try upgrading DBD::mysql as well. For the missing component, that was a bug in the frontpage template, it's fixed in 0.217. Looks like you're almost there!

d.

Direct Responses: Write a response
Posted on 2005-02-15 00:43:10-08 by davebaird in response to 93
Re: getting started (cont)
The MasonX::Maypole app sets up its own ApacheHandler object, it's not related to the Mason apps in the 'enclosing' directories. Although, it will possibly inherit Mason settings from the enclosing scope. I always set my Mason apps up in handler scripts, so I'm not sure how httpd.conf Mason settings from the outer app might influence the Maypole app. If you're finding settings leaking in, then you can just redefine them in the Maypole location block.
Direct Responses: 121 | Write a response
Posted on 2005-02-15 18:14:59-08 by mreece in response to 115
Re: getting started (cont)
moving the app root out of /Public/mason, to /Public/apache/beerdb, did the trick. indeed the problem was leaking settings from the /Public/mason default MasonCompRoot.

note there is a syntax error (missing close-paren) in maybe_link_view:
% if ( $object->isa( 'Maypole::Model::Base' ) {

and it should probably actually be:
% if ( ref $object && $object->isa( 'Maypole::Model::Base' ) ) {

now the question remains, MasonX::Maypole or Maypole::View::Mason ... thoughts?
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.