[Catalyst] create controller helper

Kiffin Gish kiffin.gish at planet.nl
Sun Jan 10 11:42:24 GMT 2010


Oops, I discovered the presence of two calls to make_immutable which was
causing the problem, sorry. In that case $self->is_immutable is no
longer true, and make_immutable will just not do anything and
immediately return (false).

On Sun, 2010-01-10 at 12:36 +0100, Kiffin Gish wrote:
> Turns out that make_immutable doesn't always return a true value:
> 
> ---start---
> Couldn't load class (I4::Web) because: I4/Web/Controller/Auth.pm did not
> return a true value at /usr/local/share/perl/5.10.0/Catalyst/Utils.pm
> line 281.
> Compilation failed in require
> at /home/kiffin/perl5/lib/perl5/i486-linux-gnu-thread-multi/Class/MOP.pm
> line 98.
> 
> at /home/kiffin/perl5/lib/perl5/i486-linux-gnu-thread-multi/Class/MOP.pm
> line 102
>         Class::MOP::__ANON__('I4/Web/Controller/Auth.pm did not return a
> true value at /usr...') called
> at /usr/local/share/perl/5.10.0/Try/Tiny.pm line 66
>         Try::Tiny::try('CODE(0x9393f78)', 'CODE(0x9c9b770)') called
> at /home/kiffin/perl5/lib/perl5/i486-linux-gnu-thread-multi/Class/MOP.pm
> line 107
>         Class::MOP::load_first_existing_class('I4::Web') called
> at /home/kiffin/perl5/lib/perl5/i486-linux-gnu-thread-multi/Class/MOP.pm
> line 118
>         Class::MOP::load_class('I4::Web') called
> at /usr/local/share/perl/5.10.0/Catalyst/ScriptRole.pm line 61
> 
> Catalyst::ScriptRole::_run_application('Catalyst::Script::Server=HASH(0x9fe8af8)') called at /usr/local/share/perl/5.10.0/Catalyst/Script/Server.pm line 181
> 
> Catalyst::Script::Server::run('Catalyst::Script::Server=HASH(0x9fe8af8)') called at /home/kiffin/perl5/lib/perl5/i486-linux-gnu-thread-multi/Class/MOP/Method/Wrapped.pm line 48
> 
> Class::MOP::Method::Wrapped::__ANON__('Catalyst::Script::Server=HASH(0x9fe8af8)') called at /home/kiffin/perl5/lib/perl5/i486-linux-gnu-thread-multi/Class/MOP/Method/Wrapped.pm line 89
> 
> Catalyst::Script::Server::run('Catalyst::Script::Server=HASH(0x9fe8af8)') called at /usr/local/share/perl/5.10.0/Catalyst/ScriptRunner.pm line 20
>         Catalyst::ScriptRunner::run('Catalyst::ScriptRunner', 'I4::Web',
> 'Server') called at script/i4_web_server.pl line 8
> ---end---
> 
> If I add "1;" after make_immutable it all loads just fine. Am I doing
> something wrong?
> 
> 
> On Sat, 2010-01-09 at 15:26 +0000, Tomas Doran wrote:
> > On 9 Jan 2010, at 11:35, Kiffin Gish wrote:
> > 
> > > Yes you're right, I overlooked the presence namespace::autoclean at  
> > > the
> > > top.
> > >
> > > Checked out the documentation but don't quite understand the  
> > > difference
> > > with namespace::clean. Is the latter the same as auto except then more
> > > explicit in that only named -except methods aren't cleaned out?
> > 
> > namespace::clean removes any symbols from your package you haven't  
> > explicitly specified at the end of your package, and ergo is ordering  
> > dependent..
> > 
> > E.g.
> > 
> > package My::Example;
> > use Test::More;
> > use Acme::UNIVERSAL::cannot;
> > use Foo qw/foo/;
> > use Bar qw/bar/;
> > use namespace::clean;
> > use Quux qw/quux/;
> > 
> > ok __PACKAGE__->can('foo');
> > ok __PACKAGE__->can('bar');
> > ok __PACKAGE__->can('baz');
> > 
> > 1;
> > # Cleaning happens at end of scope, i.e. lib/My/Example.pm finishes
> > 
> > package main;
> > use My::Example;
> > use Test::More;
> > use Acme::UNIVERSAL::cannot;
> > 
> > ok My::Example->can't('foo');
> > ok My::Example->can't('bar');
> > ok My::Example->can('quux');
> > 
> > done_testing;
> > 
> > Note that the 'quux' symbol is not removed ever :)
> > 
> > namespace::autoclean uses a different mechanism to work out what to  
> > clean - rather than being ordering related, at the end of your  
> > package, it goes through the symbol table and finds all code symbols  
> > in your package. It then gets the method list from Moose and works out  
> > the set of symbols in your package which Moose doesn't consider a  
> > method - if they're not methods, then they're imported functions...  
> > The remaining list of imported functions is then removed..
> > 
> > Does this explanation make sense at all? Any chance you could make a  
> > doc patch for namespace::clean and/or namespace::autoclean to make  
> > this more clear?
> > 
> > > Also, when use Moose is used, is it no longer necessary to end the pm
> > > module with a "1;"?
> > 
> > It is never necessary to end a .pm with 1;
> > 
> > You end with _any true value_. So you can end your package with:
> > 
> > 42;
> > __PACKAGE__;
> > 'ILIKECAKE';
> > bless {}, 'FooBar';
> > 
> > or anything else you'd like to which is a true value.
> > 
> > The make_immutable method on Class::MOP::Class returns the newly  
> > immutable metaclass instance.. Which is a true value :)
> > 
> > Cheers
> > t0m
> > 
> > 
> > _______________________________________________
> > List: Catalyst at lists.scsys.co.uk
> > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> > Dev site: http://dev.catalyst.perl.org/
> 
> 


-- 
Kiffin Gish <Kiffin.Gish at planet.nl>
Gouda, The Netherlands





More information about the Catalyst mailing list