From: John Napiorkowski Date: Sun, 11 May 2008 06:37:44 +0000 (+0000) Subject: got some basic tests going and a start at how this is going to come together X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d0e2ab777136c23d0e580661234ecf6c5fcfa9cf;p=gitmo%2FMooseX-Attribute-Cached.git got some basic tests going and a start at how this is going to come together --- diff --git a/lib/MooseX/Attribute/Cached.pm b/lib/MooseX/Attribute/Cached.pm index fb0f0ac..2635443 100644 --- a/lib/MooseX/Attribute/Cached.pm +++ b/lib/MooseX/Attribute/Cached.pm @@ -2,6 +2,7 @@ package MooseX::Attribute::Cached; use Moose; + =head1 NAME MooseX::Attribute::Cached; Cache your Moose Attribute Value @@ -27,7 +28,7 @@ our $VERSION = '0.01'; package MyApp; use Moose; - use MooseX::Attribute::Cached; + with 'MooseX::Attribute::Cached'; ## Cache Storage Options Declared Manually has 'shared_key_1' => ( @@ -80,16 +81,22 @@ every across machines, presuming you are using a distributed cache, like Memcached. All instances with access to the same cache will share and update a common value. That way: -1) All instances share the same attribute slot. Updates made by one +1) All instances share the same attribute value. Updates made by one attribute are seen by all instances, even on different servers as long as -they share a distributed caching system (such as Memcached). - +they share a distributed caching system (such as Memcached). + 2) It can be a sort of 'persistance lite' although I highly recommend using a real persistance system, such as a database or L. - + 3) You could probably use this as a sort of expensive class attribute, but you will likely be more happy with L +Please keep in mind that the process of setting and getting values in and out +of the Cache is asynchronise. When a value is updated, this is no 'Publish / +Subscribe' system running to let all the instances using this attribute know it +ha been changed. Also, since the last value that was retrieved from the Cache +is stored by the instance, any references will point to this. + At this time, this supports two Cachings systems, Memcached and FastMmap. If you have need for other cache types, adding a driver for it should be easy, so please send your patches and test cases. @@ -133,7 +140,7 @@ L =head1 COPYRIGHT & LICENSE -Copyright 2008 John Napiorkowski, all rights reserved. +Copyright 2008 John Napiorkowski This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/t/000_load.t b/t/000_load.t index 8904363..823ed72 100644 --- a/t/000_load.t +++ b/t/000_load.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More plan => 1; +use Test::More tests => 1; BEGIN { diff --git a/t/001_basic.t b/t/001_basic.t index e06c4cc..788a9d5 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,7 +3,12 @@ use strict; use warnings; -use Test::More plan => 1; +use Test::More tests => 3; +use Test::Moose; + +BEGIN { + use_ok('Moose'); +} =head1 NAME @@ -22,13 +27,89 @@ L based caching server: This package defines the following tests. -=head2 Create Test Class +=head2 Define Test Class Create a class that uses L and has some attributes that are cached. =cut +{ + ## Stub for the meta attribute trait. + package MooseX::Attribute::Cached::Meta::Attribute::Trait::Cached; + use Moose::Role; + + has 'cache' => ( + is=>'ro', + ); + + around 'set_value' => sub { + my ($set_value, $self, $instance, $value) = @_; + warn "detected set_value"; + $self->$set_value($value); + }; + + 1; + + ## meta attribute needs registering. + package Moose::Meta::Attribute::Custom::Trait::Cached; + sub register_implementation { + 'MooseX::Attribute::Cached::Meta::Attribute::Trait::Cached'; + } + + 1; + + ## Test Class + + package MooseX::Attribute::Cached::Test; + use Moose; + + has 'manual_config' => ( + is=>'rw', + traits=>['Cached'], + ); + + 1; +} + + +=head2 Test Instantiation + +Can we create a test instance and make sure it's basic methods work as we +expect. + +=cut + +ok my $cached_attrs = MooseX::Attribute::Cached::Test->new() + => 'Created a good Object'; + +isa_ok $cached_attrs => 'MooseX::Attribute::Cached::Test' + => 'Got the correct Object'; + + ## Let's create a couple extra instances that all hook up to this given + ## caching system for attributes. + + my @instances = map { + MooseX::Attribute::Cached::Test->new() + } (1..5); + + +=head2 Test Cached Attributes. + +Check that the stores the values, that the lazy builders work, that the +inflater/deflaters work, etc. + +=cut + +$cached_attrs->manual_config(1); +$cached_attrs->manual_config(2); +use Data::Dump qw/dump/; + +warn dump $cached_attrs->meta; + +=head2 Test Cache Object. + +Tests to make sure the Underlying Cached object is behavior as expected. =head1 AUTHOR @@ -36,7 +117,7 @@ John Napiorkowski, C<< >> =head1 COPYRIGHT & LICENSE -Copyright 2008 John Napiorkowski, all rights reserved. +Copyright 2008 John Napiorkowski This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.