[Catalyst-commits] r6836 - in
trunk/Catalyst-Component-ACCEPT_CONTEXT: .
lib/Catalyst/Component t t/lib/TestApp/Controller
jrockway at dev.catalyst.perl.org
jrockway at dev.catalyst.perl.org
Tue Sep 4 21:46:32 GMT 2007
Author: jrockway
Date: 2007-09-04 21:46:31 +0100 (Tue, 04 Sep 2007)
New Revision: 6836
Added:
trunk/Catalyst-Component-ACCEPT_CONTEXT/t/preserve-object.t
Modified:
trunk/Catalyst-Component-ACCEPT_CONTEXT/Changes
trunk/Catalyst-Component-ACCEPT_CONTEXT/lib/Catalyst/Component/ACCEPT_CONTEXT.pm
trunk/Catalyst-Component-ACCEPT_CONTEXT/t/02-live-stash.t
trunk/Catalyst-Component-ACCEPT_CONTEXT/t/lib/TestApp/Controller/Root.pm
Log:
add more tests (for memory cycles); add test for preserving $self; make ACCEPT_CONTEXT preserve the self ref if SUPER allows; tag 0.04
Modified: trunk/Catalyst-Component-ACCEPT_CONTEXT/Changes
===================================================================
--- trunk/Catalyst-Component-ACCEPT_CONTEXT/Changes 2007-09-04 17:50:52 UTC (rev 6835)
+++ trunk/Catalyst-Component-ACCEPT_CONTEXT/Changes 2007-09-04 20:46:31 UTC (rev 6836)
@@ -1,5 +1,8 @@
Revision history for Catalyst-Component-ACCEPT_CONTEXT
+0.04 4 Sep 2007
+ Be less invasive; return the same $self each time.
+
0.03 13 Jul 2007
Weaken context.
Modified: trunk/Catalyst-Component-ACCEPT_CONTEXT/lib/Catalyst/Component/ACCEPT_CONTEXT.pm
===================================================================
--- trunk/Catalyst-Component-ACCEPT_CONTEXT/lib/Catalyst/Component/ACCEPT_CONTEXT.pm 2007-09-04 17:50:52 UTC (rev 6835)
+++ trunk/Catalyst-Component-ACCEPT_CONTEXT/lib/Catalyst/Component/ACCEPT_CONTEXT.pm 2007-09-04 20:46:31 UTC (rev 6836)
@@ -15,11 +15,11 @@
=head1 VERSION
-Version 0.03
+Version 0.04
=cut
-our $VERSION = '0.03';
+our $VERSION = '0.04';
=head1 SYNOPSIS
@@ -49,8 +49,13 @@
=head2 ACCEPT_CONTEXT
Catalyst calls this method to give the current context to your model.
-You should never call it directly.
+You should never call it directly.
+Note that a new instance of your component isn't created. All we do
+here is shove C<$c> into your component. ACCEPT_CONTEXT allows for
+other behavior that may be more useful; if you want something else to
+happen just implement it yourself.
+
See L<Catalyst::Component> for details.
=cut
@@ -59,10 +64,10 @@
my $self = shift;
my $context = shift;
- my $new = bless({ %$self, context => $context }, ref($self));
- weaken($new->{context});
+ $self->{context} = $context;
+ weaken($self->{context});
- return $new->NEXT::ACCEPT_CONTEXT($context, @_) || $new;
+ return $self->NEXT::ACCEPT_CONTEXT($context, @_) || $self;
}
=head2 COMPONENT
Modified: trunk/Catalyst-Component-ACCEPT_CONTEXT/t/02-live-stash.t
===================================================================
--- trunk/Catalyst-Component-ACCEPT_CONTEXT/t/02-live-stash.t 2007-09-04 17:50:52 UTC (rev 6835)
+++ trunk/Catalyst-Component-ACCEPT_CONTEXT/t/02-live-stash.t 2007-09-04 20:46:31 UTC (rev 6836)
@@ -1,15 +1,13 @@
-#!/usr/bin/perl
-# 02-live-stash.t
# Copyright (c) 2007 Jonathan Rockway <jrockway at cpan.org>
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
use FindBin qw($Bin);
use lib "$Bin/lib";
use Catalyst::Test qw(TestApp);
-is( get('/stash'), 'it worked', q{stashing doesn't leak} );
-ok( get('/cycle'), 'no cycles');
-
+is( get('/stash'), 'it worked', q{stashing works} );
+is( get('/cycle'), '1', 'no cycles');
+is( get('/weak_cycle'), '1', 'found weak cycle');
Modified: trunk/Catalyst-Component-ACCEPT_CONTEXT/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-Component-ACCEPT_CONTEXT/t/lib/TestApp/Controller/Root.pm 2007-09-04 17:50:52 UTC (rev 6835)
+++ trunk/Catalyst-Component-ACCEPT_CONTEXT/t/lib/TestApp/Controller/Root.pm 2007-09-04 20:46:31 UTC (rev 6836)
@@ -40,11 +40,20 @@
my ($self, $c) = @_;
$c->model('StashMe')->test;
my $cycle_ok = 1;
- use Data::Dumper;
my $got_cycle = sub { $cycle_ok = 0 };
+ find_cycle($c, $got_cycle);
$c->res->body($cycle_ok);
}
+sub weak_cycle :Global {
+ my ($self, $c) = @_;
+ $c->model('StashMe')->test;
+ my $cycle_ok = 0;
+ my $got_cycle = sub { $cycle_ok = 1 };
+ find_weakened_cycle($c, $got_cycle);
+ $c->res->body($cycle_ok);
+}
+
1;
Added: trunk/Catalyst-Component-ACCEPT_CONTEXT/t/preserve-object.t
===================================================================
--- trunk/Catalyst-Component-ACCEPT_CONTEXT/t/preserve-object.t (rev 0)
+++ trunk/Catalyst-Component-ACCEPT_CONTEXT/t/preserve-object.t 2007-09-04 20:46:31 UTC (rev 6836)
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 4;
+
+my $app = { app => 'oh yeah' };
+
+my $foo = Foo->COMPONENT($app, { args => 'yes' });
+is $foo->{args}, 'yes', 'foo created';
+is $foo->context->{app}, 'oh yeah', 'got app';
+
+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';
+
+{
+ package Foo;
+ use base qw/Catalyst::Component::ACCEPT_CONTEXT Catalyst::Component/;
+
+ sub new {
+ my $class = shift;
+ return $class->NEXT::new(@_);
+ }
+
+}
More information about the Catalyst-commits
mailing list