From: John Napiorkowski Date: Fri, 9 May 2008 23:12:36 +0000 (+0000) Subject: initial checkin for MooseX-Attribute-Cached X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cf0ef7c5f07fb6c844045db6c9cc53935004c5c5;p=gitmo%2FMooseX-Attribute-Cached.git initial checkin for MooseX-Attribute-Cached --- cf0ef7c5f07fb6c844045db6c9cc53935004c5c5 diff --git a/Changes b/Changes new file mode 100644 index 0000000..bd03924 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for MooseX-Attribute-Cached + +0.01 09 May 2008 + First version, released on an unsuspecting world. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/MANIFEST @@ -0,0 +1 @@ + diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..3009aa8 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,17 @@ +# version control +\bCVS +(^|/)\. + +# CPAN chain files +^MANIFEST +^Makefile +^META.yml$ +^blib/ +^inc/ + +# packages +\.zip$ +\.tar\.gz$

i + +# temporarily kept old files +^archive/ \ No newline at end of file diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..6a05d21 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,18 @@ +use inc::Module::Install; + +perl_version '5.008006'; + +name 'MooseX-Attribute-Cached'; +all_from 'lib/MooseX/Attribute/Cached.pm'; +author 'John Napiorkowski '; + +requires 'Moose' => '0.42'; + +build_requires 'Test::More' => '0.70'; +build_requires 'Test::Pod' => '1.14'; +build_requires 'Test::Pod::Coverage' => '1.08'; + +auto_install; +tests "t/*.t t/*/*.t"; +WriteAll; + diff --git a/README b/README new file mode 100644 index 0000000..84f3c49 --- /dev/null +++ b/README @@ -0,0 +1,55 @@ +MooseX-Attribute-Cached + +This is an extension for your Moose based classes to make your attributes +set and get their values from a cache system, rather than from the default +perl memory perl instance storage. That way: + + 1) All instances share the same attribute slot. 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). + + 2) It can be a sort of 'persistance lite' although I highly recommend using + a real persistance system, such as a database or MooseX::Storage. + + 3) You could probably use this as a sort of expensive class attribute, but + you will likely be more happy with MooseX::ClassAttribute + + +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 MooseX::Attribute::Cached + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-Cached + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/MooseX-Attribute-Cached + + CPAN Ratings + http://cpanratings.perl.org/d/MooseX-Attribute-Cached + + Search CPAN + http://search.cpan.org/dist/MooseX-Attribute-Cached + + +COPYRIGHT AND LICENCE + +Copyright (C) 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/docs/rfc.txt b/docs/rfc.txt new file mode 100644 index 0000000..58bd9f8 --- /dev/null +++ b/docs/rfc.txt @@ -0,0 +1,2 @@ + ## MooseX::Attribute::Cached; Store the value of your Moose Attributes in a ## cached storage. The purpose of this is to faciliate sharing of attribute ## values over various processes or every across machines, presuming you are ## using a distributed cache, like Memcached. All instance with access to ## the same cache will share and update a common value. ## Proposed Directory Structure MooseX/ Attribute/ Cached.pm Cached/ Storage.pm Storage/ + FastMmap.pm Memcached.pm Meta/ Attribute/ Trait/ Cached.pm ## Example application and syntax usage package MyApp; use Moose; with 'MooseX::Attribute::Cached'; ## Cache Storage Options Declared Manually has 'shared_key_1' => ( traits => ['Cached'], cache_storage => ['Memcached' => { 'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212"], }], %other_attribute_options_1, ); ## This attribute get's it's cache storage from a method, which can be ## called from a lazy attribute or as a package method has 'shared_key_2' => ( traits => ['Cached'], %other_attribute_options_2, ); ## Here's the provider for the attributes storage sub _cache_storage_options_shared_key_2 { ## If the calling attribute is lazy get's $self, otherwise we ## gets __PACKAGE__. Getting $self could be useful if you are reading ## the cache options from something like your config object, etc. my $self = shift @_; return [ 'Memcached' => { 'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212", "/var/sock/memcached", "10.0.0.17:11211", [ "10.0.0.17:11211", 3 ], ], 'debug' => 0, 'compress_threshold' => 10_000, }, ]; } ## Rest of your Class Definition 1; diff --git a/lib/MooseX/Attribute/Cached.pm b/lib/MooseX/Attribute/Cached.pm new file mode 100644 index 0000000..211a3b9 --- /dev/null +++ b/lib/MooseX/Attribute/Cached.pm @@ -0,0 +1,143 @@ +package MooseX::Attribute::Cached; + +use Moose; + +=head1 NAME + +MooseX::Attribute::Cached; Cache your Moose Attribute Value + +=head2 AUTHORITY + +cpan:JJNAPIORK + +=cut + +our $AUTHORITY = 'cpan:JJNAPIORK'; + +=head1 VERSION + +Version 0.01 + +=cut + +our $VERSION = '0.01'; + +=head1 SYNOPSIS + + package MyApp; + + use Moose; + with 'MooseX::Attribute::Cached.pm'; + + ## Cache Storage Options Declared Manually + has 'shared_key_1' => ( + traits => ['Cached'], + cache_storage => ['Memcached' => { + 'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212"], + }], + %other_attribute_options_1, + ); + + ## This attribute get's it's cache storage from a method, which can be + ## called from a lazy attribute or as a package method + has 'shared_key_2' => ( + traits => ['Cached'], + storage_key=>'something_different_shared_key_2', + %other_attribute_options_2, + ); + + ## Here's the provider for the attributes storage. Basically you need to + ## return the storage provider name and it's instantiation args. + sub _cache_storage_options_shared_key_2 { + ## If the calling attribute is lazy get's $self, otherwise we + ## gets __PACKAGE__. Getting $self could be useful if you are reading + ## the cache options from something like your config object, etc. + my $self = shift @_; + return [ + 'Memcached' => { + 'servers' => [ + "10.0.0.15:11211", + "10.0.0.15:11212", + "/var/sock/memcached", + "10.0.0.17:11211", + [ "10.0.0.17:11211", 3 ], + ], + 'debug' => 0, + 'compress_threshold' => 10_000, + }, + ]; + } + + ## + + 1; + +=head1 DESCRIPTION + +Store the value of your Moose Attributes in a cached storage. The purpose of +this is to faciliate sharing of attribute values over various processes or +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 +attribute are seen by all instances, even on different servers as long as +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 + +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. + +=head1 AUTHOR + +John Napiorkowski, C<< >> + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc MooseX::Attributes::Cached + +You can also look for information at: + +=over 4 + +=item * RT: CPAN's request tracker + +L + +=item * AnnoCPAN: Annotated CPAN documentation + +L + +=item * CPAN Ratings + +L + +=item * Search CPAN + +L + +=back + +=head1 SEE ALSO + +L, L, L, L, +L + +=head1 COPYRIGHT & LICENSE + +Copyright 2008 John Napiorkowski, all rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=cut + +no Moose; 1; # End of MooseX::Attributes::Cached diff --git a/t-author/pod.t b/t-author/pod.t new file mode 100644 index 0000000..4ae1af3 --- /dev/null +++ b/t-author/pod.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +eval "use Test::Pod 1.14"; +plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; + +all_pod_files_ok(); diff --git a/t-author/pod_coverage.t b/t-author/pod_coverage.t new file mode 100644 index 0000000..c59a36a --- /dev/null +++ b/t-author/pod_coverage.t @@ -0,0 +1,10 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +eval "use Test::Pod::Coverage"; +plan skip_all => "Test::Pod::Coverage required for testing POD Coverage" if $@; + +all_pod_coverage_ok(); diff --git a/t/000_load.t b/t/000_load.t new file mode 100644 index 0000000..d4bcf05 --- /dev/null +++ b/t/000_load.t @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More no_plan => 1; +use Test::Exception; + +BEGIN { + use_ok('MooseX::MetaDescription'); + + use_ok('MooseX::MetaDescription::Meta::Class'); + use_ok('MooseX::MetaDescription::Meta::Attribute'); + use_ok('MooseX::MetaDescription::Meta::Trait'); + + use_ok('MooseX::MetaDescription::Description'); +}