[Catalyst] Re: Initialization ordering, SOLVED
Dominique Quatravaux
dom at idealx.com
Thu Jun 30 16:56:23 CEST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dominique Quatravaux a écrit :
> Dear Catalyst hackers,
>
> I have a model class, Foo::M::Bar, and I want it to perform
>
> __PACKAGE__->columns(Stringify => "name");
>
> at an appropriate time.
I ended up coding my own "eval-after-load" feature just like Emacs',
and lo and behold, it's so short and easy that i'm not sure I can find
the courage to factor it out in a CPAN module of it's own :-) (name
suggestions welcome - What about Module::Pluggable::AfterInit ?)
=-=-=-=-=-=
package Foo::M::Bar;
use Foo::M::CDBI;
run_after_init Foo::M::CDBI sub {
__PACKAGE__->columns(Stringify => qw/name/);
};
=-=-=-=-=
package Foo::M::CDBI;
# Catalyst boilerplate here
use base 'Class::Data::Inheritable';
__PACKAGE__->mk_classdata("runlist");
__PACKAGE__->runlist([]);
sub run_after_init {
my ($class, $sub) = @_;
if (! defined $class->runlist) {
&$sub;
return 1;
} else {
push @{$class->runlist}, $sub;
return undef;
}
}
use NEXT;
sub new {
my ($class, $c) = @_;
$_->() foreach @{$class->runlist()};
$class->runlist(undef);
return $class->NEXT::new($c);
}
- --
Dominique QUATRAVAUX Ingénieur senior
01 44 42 00 08 IDEALX
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCxAgXMJAKAU3mjcsRApzlAJ4t/fXhVUURW8vL0J8eTQnqoKa5cwCfXzzU
XZgmCfUNctR6hVlDiaLnX6U=
=Fs6D
-----END PGP SIGNATURE-----
More information about the Catalyst
mailing list