Perl Catalyst Problem
Hi all,
I have a bit of a problem with Catalyst. I have been working through the Catalyst tutorial as found at http://search.cpan.org/~ether/Catalyst-Manual-5.9007/lib/Catalyst/Manual/Tutorial.pod . First off, this is a very good introduction to Catalyst development. I have completed chapters 0 to 8, and the code that I have entered works flawlessly when run using the myapp_server.pl. this was initally done on the provided Catalyst tutorial virtual machine image downloaded from http://cattut.shadowcat.co.uk/.
I have since moved this to my own development server, and it also works flawlessly when using the myapp_server.pl script on the new computer.
My problem is that, the exact same code, running on the exact same development computer, blows up when running as a mod_perl module under Apache. When I attempt to log in, I get the following error:
Caught exception in MyApp::Controller::Login->index "Can't use string
("Catalyst::Authentication::Store:"...) as a HASH ref while "strict
refs" in use at accessor Catalyst::Authentication::Store::DBIx::Class
::User::_user (defined at /usr/share/perl5/Catalyst/Authentication/
Store/DBIx/Class/User.pm line 12) line 5, <DATA> line 1000."
The stack trace points the failure at the line where the $c->authenticate method is called:
35: if ($username && $password) {
36: # Attempt to log the user in
37: $c->log->debug("value in \$c->authenticate is \"".Dumper($c)."\"");
38: if ($c->authenticate({ username => $username,
39: password => $password } )) {
40: # If successful, then let them use the application
41: $c->response->redirect($c->uri_for(
if i add a debug or print statement before this. the error moves to the first place where I reference the $c context object.
Again, this exact same code works with no problem when run using the myapp_server.pl. this is the only difference, the host name is the same, the ip address is the same, the code is the same, the installed perl libraries are the same, the difference in the url is one is accessed using port 3000 and the other is at port 80 (http://mytest.org:3000/ vs http://mytest.org/ ).
My environment:
My web development server is runnung Ubuntu 13.10 Server in a Virtualbox VM.
I have downloaded and installed Catalyst mostly using the packages available in the Ubuntu 13.10 repositories, although a small hand full of perl modules used by the tutorial Catalyst had to be installed via CPAN using the Catalyst project Makefile. except for a couple of PHP modules and the Catalyst stuff, this is a fresh, vanilla install of Ubuntu 13.10, choosing to install the LAMP, SSH server, and Mail Server package groups during the installation.
The apache2 configuration file, enabling the site under mod_perl on apache:
$ cat /etc/apache2/sites-enabled/004-osws-catalyst-site.conf
PerlSwitches -I/home/onestopw/lib
PerlModule MyApp
<VirtualHost mytest.org:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName osws.org
ServerAdmin webmaster@localhost
DocumentRoot /home/onestopw/root
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog /home/onestopw/logs/error.log
CustomLog /home/onestopw/logs/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# run the app from the site root directory
<Location />
SetHandler modperl
PerlResponseHandler MyApp
#Options Indexes FollowSymLinks
Order Deny,Allow
Allow from all
Require all granted
</Location>
# however, server static content with apache alone
<Location /static>
SetHandler default-handler
</Location>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
this apache.conf file was modeled on the file described at http://search.cpan.org/~flora/Catalyst-Engine-Apache-1.16/lib/Catalyst/Engine/Apache2/MP20.pm
the site starts to work under apache mod_perl and the login page is displayed whenever any url to this site is loaded. this is also exactly what happens when run using the myapp_server.pl when no user is logged in. When I supply a user name and password on the login form and submit the form, that is when the above error occurs when running under mod_perl. When run by the myapp_server.pl script, submitting the form validates the user and password, and if valid, displays the book list page.
I believe that this error is caused by the Catalyst object not being properly blessed when running as a mod_perl module. This means that when the authenticate method is called, instead of $c being a context object with an authenticate method, it is simply a string containing "Catalyst::Authentication::Store:", the name of the object type that it is supposed to be.
At this point, I am at a loss. Something is different between the apache mod_perl environment and the myapp_server.pl environment. I am currently stepping through the execution of loading and configuration of the MyApp module, placing print STDERR lines throughout the Catalyst modules as MyApp.pm is loaded. Hopefully, the difference will become apparent, but if anyone more familiar with the inner workings of Catalyst sees something obvious, please let me know.
My project is stuck in the mud at this point, since there would be no point in developing it using Catalyst if Catalyst will not actually work under apache.
Thanks,
William Anderson
Hi all,
I have a bit of a problem with Catalyst. I have been working through the Catalyst tutorial as found at http://search.cpan.org/~ether/Catalyst-Manual-5.9007/lib/Catalyst/Manual/Tutorial.pod . First off, this is a very good introduction to Catalyst development. I have completed chapters 0 to 8, and the code that I have entered works flawlessly when run using the myapp_server.pl. this was initally done on the provided Catalyst tutorial virtual machine image downloaded from http://cattut.shadowcat.co.uk/.
I have since moved this to my own development server, and it also works flawlessly when using the myapp_server.pl script on the new computer.
My problem is that, the exact same code, running on the exact same development computer, blows up when running as a mod_perl module under Apache. When I attempt to log in, I get the following error:
Caught exception in MyApp::Controller::Login->index "Can't use string
("Catalyst::Authentication::Store:"...) as a HASH ref while "strict
refs" in use at accessor Catalyst::Authentication::Store::DBIx::Class
::User::_user (defined at /usr/share/perl5/Catalyst/Authentication/
Store/DBIx/Class/User.pm line 12) line 5, <DATA> line 1000."
The stack trace points the failure at the line where the $c->authenticate method is called:
35: if ($username && $password) {
36: # Attempt to log the user in
37: $c->log->debug("value in \$c->authenticate is \"".Dumper($c)."\"");
38: if ($c->authenticate({ username => $username,
39: password => $password } )) {
40: # If successful, then let them use the application
41: $c->response->redirect($c->uri_for(
if i add a debug or print statement before this. the error moves to the first place where I reference the $c context object.
Again, this exact same code works with no problem when run using the myapp_server.pl. this is the only difference, the host name is the same, the ip address is the same, the code is the same, the installed perl libraries are the same, the difference in the url is one is accessed using port 3000 and the other is at port 80 (http://mytest.org:3000/ vs http://mytest.org/ ).
My environment:
My web development server is runnung Ubuntu 13.10 Server in a Virtualbox VM.
I have downloaded and installed Catalyst mostly using the packages available in the Ubuntu 13.10 repositories, although a small hand full of perl modules used by the tutorial Catalyst had to be installed via CPAN using the Catalyst project Makefile. except for a couple of PHP modules and the Catalyst stuff, this is a fresh, vanilla install of Ubuntu 13.10, choosing to install the LAMP, SSH server, and Mail Server package groups during the installation.
The apache2 configuration file, enabling the site under mod_perl on apache:
$ cat /etc/apache2/sites-enabled/004-osws-catalyst-site.conf
PerlSwitches -I/home/onestopw/lib
PerlModule MyApp
<VirtualHost mytest.org:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName osws.org
ServerAdmin webmaster@localhost
DocumentRoot /home/onestopw/root
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog /home/onestopw/logs/error.log
CustomLog /home/onestopw/logs/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# run the app from the site root directory
<Location />
SetHandler modperl
PerlResponseHandler MyApp
#Options Indexes FollowSymLinks
Order Deny,Allow
Allow from all
Require all granted
</Location>
# however, server static content with apache alone
<Location /static>
SetHandler default-handler
</Location>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
this apache.conf file was modeled on the file described at http://search.cpan.org/~flora/Catalyst-Engine-Apache-1.16/lib/Catalyst/Engine/Apache2/MP20.pm
the site starts to work under apache mod_perl and the login page is displayed whenever any url to this site is loaded. this is also exactly what happens when run using the myapp_server.pl when no user is logged in. When I supply a user name and password on the login form and submit the form, that is when the above error occurs when running under mod_perl. When run by the myapp_server.pl script, submitting the form validates the user and password, and if valid, displays the book list page.
I believe that this error is caused by the Catalyst object not being properly blessed when running as a mod_perl module. This means that when the authenticate method is called, instead of $c being a context object with an authenticate method, it is simply a string containing "Catalyst::Authentication::Store:", the name of the object type that it is supposed to be.
At this point, I am at a loss. Something is different between the apache mod_perl environment and the myapp_server.pl environment. I am currently stepping through the execution of loading and configuration of the MyApp module, placing print STDERR lines throughout the Catalyst modules as MyApp.pm is loaded. Hopefully, the difference will become apparent, but if anyone more familiar with the inner workings of Catalyst sees something obvious, please let me know.
My project is stuck in the mud at this point, since there would be no point in developing it using Catalyst if Catalyst will not actually work under apache.
Thanks,
William Anderson