Tie-CHI
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
Revision history for Tie-CHI
** denotes an incompatible change
0.02 Nov 6, 2011
- Declare dependencies CHI and Scalar::Util - RT #72031 - Andreas Koenig
0.01 Oct 6, 2011
- Initial version
This is the Perl distribution Tie-CHI.
Installing Tie-CHI is straightforward.
## Installation with cpanm
If you have cpanm, you only need one line:
% cpanm Tie::CHI
If you are installing into a system-wide directory, you may need to pass the
"-S" flag to cpanm, which uses sudo to install the module:
% cpanm -S Tie::CHI
## Installing with the CPAN shell
Alternatively, if your CPAN shell is set up, you should just be able to do:
% cpan Tie::CHI
## Manual installation
As a last resort, you can manually install it. Download the tarball, untar it,
then build it:
% perl Makefile.PL
% make && make test
Then install it:
% make install
If you are installing into a system-wide directory, you may need to run:
% sudo make install
## Documentation
Tie-CHI documentation is available as POD.
You can run perldoc from a shell to read the documentation:
% perldoc Tie::CHI
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
Changes
INSTALL
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
lib/Tie/CHI.pm
t/01-use.t
t/02-tie-chi.t
{
"abstract" : "Tied hash to persistent CHI cache",
"author" : [
"Jonathan Swartz <swartz@pobox.com>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 4.200008, CPAN::Meta::Converter version 2.102400",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Tie-CHI",
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "6.30"
}
},
"runtime" : {
"requires" : {
"CHI" : 0,
"Scalar::Util" : 0
}
},
"test" : {
"requires" : {
"Test::Deep" : 0,
"Test::More" : 0
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"mailto" : "bug-tie-chi@rt.cpan.org",
"web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tie-CHI"
},
"repository" : {
"type" : "git",
"url" : "git://github.com/jonswar/perl-tie-chi.git",
"web" : "https://github.com/jonswar/perl-tie-chi"
}
},
"version" : "0.02"
}
---
abstract: 'Tied hash to persistent CHI cache'
author:
- 'Jonathan Swartz <swartz@pobox.com>'
build_requires:
Test::Deep: 0
Test::More: 0
configure_requires:
ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.200008, CPAN::Meta::Converter version 2.102400'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Tie-CHI
requires:
CHI: 0
Scalar::Util: 0
resources:
bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tie-CHI
repository: git://github.com/jonswar/perl-tie-chi.git
version: 0.02
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
'ABSTRACT' => 'Tied hash to persistent CHI cache',
'AUTHOR' => 'Jonathan Swartz <swartz@pobox.com>',
'BUILD_REQUIRES' => {
'Test::Deep' => '0',
'Test::More' => '0'
},
'CONFIGURE_REQUIRES' => {
'ExtUtils::MakeMaker' => '6.30'
},
'DISTNAME' => 'Tie-CHI',
'EXE_FILES' => [],
'LICENSE' => 'perl',
'NAME' => 'Tie::CHI',
'PREREQ_PM' => {
'CHI' => '0',
'Scalar::Util' => '0'
},
'VERSION' => '0.02',
'test' => {
'TESTS' => 't/*.t'
}
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
NAME
Tie::CHI - Tied hash to persistent CHI cache
VERSION
version 0.02
SYNOPSIS
use Tie::CHI;
my %cache;
# Pass CHI options to tie
#
tie %cache, 'Tie::CHI', { driver => 'File', root_dir => '/path/to/root' };
tie %cache, 'Tie::CHI',
{
driver => 'Memcached::libmemcached',
namespace => 'homepage',
servers => [ "10.0.0.15:11211", "10.0.0.15:11212" ],
default_expires_in => '10 min'
} );
# or pass an existing CHI object
#
my $chi_object = CHI->new(...);
tie %cache, 'Tie::CHI', $chi_object;
# Perform cache operations
#
my $customer = $cache{$name};
if ( !defined $customer ) {
$customer = get_customer_from_db($name);
$cache{$name} = $customer;
}
delete( $cache{$name} );
# Break the binding
#
untie(%cache);
DESCRIPTION
Tie::CHI implements a tied hash connected to a CHI cache. It can be used
with any of CHI's backends (File, Memcached, DBI, etc.)
Usage is one of the following:
tie %cache, 'Tie::CHI', $hash_of_chi_options;
tie %cache, 'Tie::CHI', $existing_chi_cache;
A read/write/delete on the tied hash will result in a
`get'/`set'/`remove' on the underlying cache. `keys' and `each' will be
supported if the underlying CHI driver supports `get_keys'.
There is no way to specify expiration for an individual `set', but you
can pass `expires_in', `expires_at' and/or `expires_variance' to the tie
to specify default expiration. e.g.
tie %cache, 'Tie::CHI', {
namespace => 'products',
driver => 'DBI',
dbh => DBIx::Connector->new(...),
expires_in => '4 hours',
expires_variance => '0.2'
};
SUPPORT AND DOCUMENTATION
Questions and feedback are welcome, and should be directed to the
perl-cache mailing list:
http://groups.google.com/group/perl-cache-discuss
Bugs and feature requests will be tracked at RT:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tie-CHI
bug-tie-chi@rt.cpan.org
The latest source code can be browsed and fetched at:
http://github.com/jonswar/perl-tie-chi/tree/master
git clone git://github.com/jonswar/perl-tie-chi.git
SEE ALSO
CHI
AUTHOR
Jonathan Swartz <swartz@pobox.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
lib/Tie/CHI.pm view on Meta::CPAN
package Tie::CHI;
BEGIN {
$Tie::CHI::VERSION = '0.02';
}
use CHI;
use Scalar::Util qw(blessed);
use strict;
use warnings;
sub TIEHASH {
my ( $class, $cache ) = @_;
if ( ref($cache) eq 'HASH' ) {
$cache = CHI->new(%$cache);
}
elsif ( !( blessed($cache) && $cache->isa('CHI::Driver') ) ) {
die "must pass a hash of options or a CHI object";
}
my $self = bless { _cache => $cache }, $class;
return $self;
}
sub _cache {
return $_[0]->{_cache};
}
sub STORE {
t/02-tie-chi.t view on Meta::CPAN
#!/usr/bin/env perl
#
use Tie::CHI;
use File::Temp qw(tempdir);
use Test::More;
use Test::Deep;
use strict;
use warnings;
my $root_dir = tempdir( 'tie-chi-XXXX', TMPDIR => 1, CLEANUP => 1 );
my %cache;
tie %cache, 'Tie::CHI', { driver => 'File', root_dir => $root_dir };
test();
untie %cache;
my $datastore = {};
tie %cache, 'Tie::CHI', CHI->new( driver => 'Memory', datastore => $datastore );
test();
done_testing();
sub test {
ok( !%cache, "cache is empty" );
is( $cache{foo}, undef, "foo not defined" );
@cache{qw(foo bar baz blargh)} = ( 5, 6, [ 7, 8 ], 9 );
ok( scalar(%cache), "cache is not empty" );
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.562 second using v1.00-cache-2.02-grep-82fe00e-cpan-503542c4f10 )