[Catalyst-commits] r6457 - in trunk/Catalyst-Component-InstancePerContext: . lib/Catalyst/Component t

groditi at dev.catalyst.perl.org groditi at dev.catalyst.perl.org
Wed Jun 6 22:30:03 GMT 2007


Author: groditi
Date: 2007-06-06 22:30:03 +0100 (Wed, 06 Jun 2007)
New Revision: 6457

Added:
   trunk/Catalyst-Component-InstancePerContext/Changes
   trunk/Catalyst-Component-InstancePerContext/README
   trunk/Catalyst-Component-InstancePerContext/t/
   trunk/Catalyst-Component-InstancePerContext/t/basic.t
Modified:
   trunk/Catalyst-Component-InstancePerContext/lib/Catalyst/Component/InstancePerContext.pm
Log:
going to cpan i guess

Added: trunk/Catalyst-Component-InstancePerContext/Changes
===================================================================
--- trunk/Catalyst-Component-InstancePerContext/Changes	                        (rev 0)
+++ trunk/Catalyst-Component-InstancePerContext/Changes	2007-06-06 21:30:03 UTC (rev 6457)
@@ -0,0 +1,3 @@
+
+0.001000 2007-06-06
+        - Initial Release

Added: trunk/Catalyst-Component-InstancePerContext/README
===================================================================
--- trunk/Catalyst-Component-InstancePerContext/README	                        (rev 0)
+++ trunk/Catalyst-Component-InstancePerContext/README	2007-06-06 21:30:03 UTC (rev 6457)
@@ -0,0 +1,38 @@
+Catalyst-Component-InstancePerContext
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+    perl Makefile.PL
+    make
+    make test
+    make install
+
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the perldoc command.
+
+    perldoc Catalyst::Component::InstancePerContext
+
+You can also look for information at:
+
+    Search CPAN
+        http://search.cpan.org/dist/Catalyst-Component-InstancePerContext
+
+    CPAN Request Tracker:
+        http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Component-InstancePerContext
+
+    AnnoCPAN, annotated CPAN documentation:
+        http://annocpan.org/dist/Catalyst-Component-InstancePerContext
+
+    CPAN Ratings:
+        http://cpanratings.perl.org/d/Catalyst-Component-InstancePerContext
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2006 Guillermo Roditi
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.

Modified: trunk/Catalyst-Component-InstancePerContext/lib/Catalyst/Component/InstancePerContext.pm
===================================================================
--- trunk/Catalyst-Component-InstancePerContext/lib/Catalyst/Component/InstancePerContext.pm	2007-06-04 06:13:56 UTC (rev 6456)
+++ trunk/Catalyst-Component-InstancePerContext/lib/Catalyst/Component/InstancePerContext.pm	2007-06-06 21:30:03 UTC (rev 6457)
@@ -2,7 +2,11 @@
 
 use Moose::Role;
 use Scalar::Util qw/blessed refaddr/;
+use strict;
+use warnings;
 
+our $VERSION = '0.001000';
+
 requires 'build_per_context_instance';
 
 # Hi, this is why I exist:

Added: trunk/Catalyst-Component-InstancePerContext/t/basic.t
===================================================================
--- trunk/Catalyst-Component-InstancePerContext/t/basic.t	                        (rev 0)
+++ trunk/Catalyst-Component-InstancePerContext/t/basic.t	2007-06-06 21:30:03 UTC (rev 6457)
@@ -0,0 +1,51 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Scalar::Util qw/refaddr/;
+
+{
+  package TestModule;
+  use Moose;
+}
+
+{
+  package TestComponent;
+
+  use Moose;
+  with "Catalyst::Component::InstancePerContext";
+
+  sub build_per_context_instance {
+    return TestModule->new;
+  }
+}
+
+{
+  package MyMockContext;
+  use Moose;
+  has stash => (isa => 'HashRef', is => 'ro', required => 1, default => sub{{}});
+}
+
+use Test::More tests => 7;
+
+my $ctx1 = MyMockContext->new;
+isa_ok($ctx1, 'MyMockContext');
+
+my $component = TestComponent->new;
+isa_ok($component, 'TestComponent');
+can_ok($component, 'ACCEPT_CONTEXT', 'build_per_context_instance');
+
+my $instance = TestComponent->ACCEPT_CONTEXT($ctx1);
+is(refaddr( TestComponent->ACCEPT_CONTEXT($ctx1) ), refaddr $instance,
+   'does not create second instance');
+is(refaddr $ctx1->stash->{"__InstancePerContext_TestComponent"}, refaddr $instance,
+   'Correct key storage');
+
+my $instance2 = $component->ACCEPT_CONTEXT($ctx1);
+my $addr = refaddr $component;
+is(refaddr $component->ACCEPT_CONTEXT($ctx1), refaddr $instance2,
+   'does not create second instance');
+is(refaddr $ctx1->stash->{"__InstancePerContext_${addr}"}, refaddr $instance2,
+   'Correct key storage');
+
+




More information about the Catalyst-commits mailing list