[Catalyst] user_exists dies when used from Test::WWW::Mechanize::Catalyst

Robert Rothenberg robrwo at gmail.com
Mon Jun 25 09:48:17 GMT 2012

Several DBIC classes in our application have been customized with a method


that takes a Catalyst context and checks if the user is logged in, and can
modify the record.  This seems to work fine when manually testing various

But we want to write tests for this that use Test::WWW::Mechanize::Catalyst
to log a user in (and possibly run some actions that may change the user's
access), and then manually fetch a record from DBIC and test whether the
currently logged-in user can indeed modify the record.

I want the Catalyst context from a Test::WWW::Mechanize::Catalyst object,
which I assume can be gotten using

  $c = $m->catalyst_app

although this isn't documented as far as I can tell. It seems to work find
for some functions, e.g.

  $data = $c->model($TABLE)->find(...)

So my test script fetches some pages and logs a user in. But $c->user_exists

You must pass a package name and it cannot be blessed at
/usr/local/lib/perl/5.10.1/Class/MOP/Class.pm line 43
	Class::MOP::Class::initialize('Class::MOP::Class', '') called at
/usr/local/lib/perl/5.10.1/Class/MOP/Attribute.pm line 297
	Class::MOP::Attribute::get_raw_value('Moose::Meta::Class::__ANON__::SERIAL::12=HASH(0x5291f60)', 'MyApp') called at /usr/local/lib/perl/5.10.1/Class/MOP/Attribute.pm line 291
	Class::MOP::Attribute::get_value('Moose::Meta::Class::__ANON__::SERIAL::12=HASH(0x5291f60)', 'MyApp') called at /usr/local/lib/perl/5.10.1/Moose/Meta/Attribute.pm line 841
	Moose::Meta::Attribute::get_value('Moose::Meta::Class::__ANON__::SERIAL::12=HASH(0x5291f60)', 'MyApp') called at /usr/local/share/perl/5.10.1/MooseX/Emulate/Class/Accessor/Fast/Meta/Accessor.pm line 13
	Catalyst::Plugin::Authentication::_user('MyApp') called at
/usr/local/share/perl/5.10.1/Catalyst/Plugin/Authentication.pm line 56
	Catalyst::Plugin::Authentication::user_exists('MyApp') called at t/test.t
line 37

Is this a bug in Moose or just a side effect due to my getting the Catalyst
context in an unorthodox way.

I'd rather not use Catalyst::Test, since it means having to replicate a lot
of the functionality of Test::WWW::Mechanize::Catalyst (not to mention that
we have various helper functions for testing our application that already
use TWMC.)

More information about the Catalyst mailing list