initial checkin for MooseX-Attribute-Cached
John Napiorkowski [Fri, 9 May 2008 23:12:36 +0000 (23:12 +0000)]
Changes [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
MANIFEST.SKIP [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
docs/rfc.txt [new file with mode: 0644]
lib/MooseX/Attribute/Cached.pm [new file with mode: 0644]
t-author/pod.t [new file with mode: 0644]
t-author/pod_coverage.t [new file with mode: 0644]
t/000_load.t [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
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 (file)
index 0000000..8b13789
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1 @@
+
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644 (file)
index 0000000..3009aa8
--- /dev/null
@@ -0,0 +1,17 @@
+# version control
+\bCVS
+(^|/)\.
+
+# CPAN chain files
+^MANIFEST
+^Makefile
+^META.yml$
+^blib/
+^inc/
+
+# packages
+\.zip$
+\.tar\.gz$</code></p></div>i
+
+# temporarily kept old files
+^archive/
\ No newline at end of file
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..6a05d21
--- /dev/null
@@ -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 <jjn1056@yahoo.com>';
+
+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 (file)
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 (file)
index 0000000..58bd9f8
--- /dev/null
@@ -0,0 +1,2 @@
+       ## MooseX::Attribute::Cached; Store the value of your Moose Attributes in a\r    ## cached storage.  The purpose of this is to faciliate sharing of attribute\r   ## values over various processes or every across machines, presuming you are\r   ## using a distributed cache, like Memcached.  All instance with access to\r     ## the same cache will share and update a common value.\r        \r       ## Proposed Directory Structure\r\r       MooseX/\r                Attribute/\r                     Cached.pm\r                      Cached/\r                                Storage.pm\r                             Storage/
+\r                                      FastMmap.pm\r                                    Memcached.pm\r                                   <other storage types>\r                          Meta/\r                                  Attribute/\r                                             Trait/\r                                                 Cached.pm\r\r\r    ## Example application and syntax usage         \r                                                       \r       package MyApp;\r \r       use Moose;\r     with 'MooseX::Attribute::Cached';\r\r     ## Cache Storage Options Declared Manually\r     has 'shared_key_1' => (\r                traits => ['Cached'],\r          cache_storage => ['Memcached' => {\r                     'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212"],\r          }], \r           %other_attribute_options_1,\r    );\r     \r       ## This attribute get's it's cache storage from a method, which can be\r ## called from a lazy attribute or as a package method\r has 'shared_key_2' => (\r                traits => ['Cached'], \r         %other_attribute_options_2,\r    );\r     \r       ## Here's the provider for the attributes storage\r      sub _cache_storage_options_shared_key_2 {\r              ## If the calling attribute is lazy get's $self, otherwise we\r          ## gets __PACKAGE__.  Getting $self could be useful if you are reading\r         ## the cache options from something like your config object, etc.\r              my $self = shift @_;\r           return [\r                       'Memcached' => {\r                               'servers' => [\r                                 "10.0.0.15:11211", \r                                    "10.0.0.15:11212", \r                                    "/var/sock/memcached",\r                                 "10.0.0.17:11211",\r                                     [ "10.0.0.17:11211", 3 ],\r                              ],\r                             'debug' => 0,\r                          'compress_threshold' => 10_000,\r                        },\r             ];\r     }\r      \r       ## Rest of your Class Definition\r       \r       1;\r\r
diff --git a/lib/MooseX/Attribute/Cached.pm b/lib/MooseX/Attribute/Cached.pm
new file mode 100644 (file)
index 0000000..211a3b9
--- /dev/null
@@ -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,
+                       },
+               ];
+       }
+       
+       ## <Rest of your Class Definition>
+       
+       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<MooseX::Storage>.
+       
+3) You could probably use this as a sort of expensive class attribute, but
+you will likely be more happy with L<MooseX::ClassAttribute>
+
+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<< <john.napiorkowski at takkle.com> >>
+
+=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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attributes-Cached>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/MooseX-Attributes-Cached>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/MooseX-Attributes-Cached>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/MooseX-Attributes-CachedF>
+
+=back
+
+=head1 SEE ALSO
+
+L<Moose>, L<MooseX::ClassAttribute>, L<MooseX::Storage>, L<Cache::FastMmap>,
+L<Cache::Memcached>
+
+=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 (file)
index 0000000..4ae1af3
--- /dev/null
@@ -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 (file)
index 0000000..c59a36a
--- /dev/null
@@ -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 (file)
index 0000000..d4bcf05
--- /dev/null
@@ -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');
+}