Using this module is somewhat of a hack. Changing the state of your
objects on every request is a pretty braindead way of doing OO. If
you want your application to be brain-live, then you should use
-L<Catalyst::Component::InstancePerContext|Catalyst::Component::InstancePerContext>.
+L<Catalyst::Component::InstancePerContext>.
Instead of doing this on every request (which is basically
what this module does):
Jonathan Rockway, C<< <jrockway at cpan.org> >>
+Patches contributed and maintained by:
+
+=over
+
+=item Rafael Kitover (Caelum)
+
+=item Tomas Doran (t0m) C<< <bobtfish@bobtfish.net> >>
+
+=back
+
=head1 BUGS
Please report any bugs or feature requests to
=back
+=head1 Source code
+
+The source code for this project can be found at:
+
+ git://git.shadowcat.co.uk/catagits/Catalyst-Component-ACCEPT_CONTEXT
+
=head1 COPYRIGHT & LICENSE
Copyright 2007 Jonathan Rockway.
#!/usr/bin/env perl
-
use strict;
use warnings;
-use Test::More tests => 4;
-
-my $app = 'MyApp';
-my $foo = Foo->COMPONENT($app, { args => 'yes' });
-is $foo->{args}, 'yes', 'foo created';
-is $foo->context->app, 'oh yeah', 'got app';
+{
+ package MyApp;
+ use Moose;
+ use Catalyst;
+ no Moose;
-my $ctx = { ctx => 'it is' };
-my $foo2 = $foo->ACCEPT_CONTEXT($ctx);
-is $foo, $foo2, 'foo and foo2 are the same ref';
-is $foo->context->{ctx}, 'it is', 'got ctx';
+ sub _is_this_the_app { 'oh yeah' }
+}
{
package Foo;
my $class = shift;
return $class->next::method(@_);
}
-
- package MyApp;
- use Catalyst;
- sub app { 'oh yeah' }
}
+
+use Test::More tests => 4;
+use Scalar::Util qw/refaddr/;
+
+my $app_class = 'MyApp';
+
+my $foo = Foo->COMPONENT($app_class, { args => 'yes' });
+is $foo->{args}, 'yes', 'foo created';
+is $foo->context->_is_this_the_app, 'oh yeah', 'got app';
+
+my $ctx = { };
+my $foo2 = $foo->ACCEPT_CONTEXT($ctx);
+is refaddr($foo), refaddr($foo2), 'foo and foo2 are the same ref';
+is refaddr($foo->context), refaddr($ctx), 'got ctx';
+