Tweaks
[catagits/Catalyst-Component-ACCEPT_CONTEXT.git] / t / preserve-object.t
CommitLineData
75f37967 1#!/usr/bin/env perl
75f37967 2use strict;
3use warnings;
75f37967 4
17c2a53f 5{
6 package MyApp;
7 use Moose;
8 use Catalyst;
9 no Moose;
75f37967 10
17c2a53f 11 sub _is_this_the_app { 'oh yeah' }
12}
75f37967 13
14{
15 package Foo;
16 use base qw/Catalyst::Component::ACCEPT_CONTEXT Catalyst::Component/;
17
18 sub new {
19 my $class = shift;
c9c41e4d 20 return $class->next::method(@_);
75f37967 21 }
75f37967 22}
17c2a53f 23
24use Test::More tests => 4;
25use Scalar::Util qw/refaddr/;
26
27my $app_class = 'MyApp';
28
29my $foo = Foo->COMPONENT($app_class, { args => 'yes' });
30is $foo->{args}, 'yes', 'foo created';
31is $foo->context->_is_this_the_app, 'oh yeah', 'got app';
32
33my $ctx = { };
34my $foo2 = $foo->ACCEPT_CONTEXT($ctx);
35is refaddr($foo), refaddr($foo2), 'foo and foo2 are the same ref';
36is refaddr($foo->context), refaddr($ctx), 'got ctx';
37