Hello community,
here is the log from the commit of package perl-Mojolicious-Plugin-CHI for
openSUSE:Factory checked in at 2014-04-25 16:11:42
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Mojolicious-Plugin-CHI (Old)
and /work/SRC/openSUSE:Factory/.perl-Mojolicious-Plugin-CHI.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Mojolicious-Plugin-CHI"
Changes:
--------
---
/work/SRC/openSUSE:Factory/perl-Mojolicious-Plugin-CHI/perl-Mojolicious-Plugin-CHI.changes
2014-04-02 17:25:17.000000000 +0200
+++
/work/SRC/openSUSE:Factory/.perl-Mojolicious-Plugin-CHI.new/perl-Mojolicious-Plugin-CHI.changes
2014-04-25 16:11:44.000000000 +0200
@@ -1,0 +2,14 @@
+Mon Apr 21 06:30:54 UTC 2014 - [email protected]
+
+- Update to version 0.09
+ * Bugfix test suite.
+
+-------------------------------------------------------------------
+Mon Apr 21 06:30:16 UTC 2014 - [email protected]
+
+- Update to version 0.08
+ * Logging now defaults to application log.
+ * Update requirements.
+ * Added commands.
+
+-------------------------------------------------------------------
Old:
----
Mojolicious-Plugin-CHI-0.07.tar.gz
New:
----
Mojolicious-Plugin-CHI-0.09.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Mojolicious-Plugin-CHI.spec ++++++
--- /var/tmp/diff_new_pack.3gVFSR/_old 2014-04-25 16:11:45.000000000 +0200
+++ /var/tmp/diff_new_pack.3gVFSR/_new 2014-04-25 16:11:45.000000000 +0200
@@ -17,7 +17,7 @@
Name: perl-Mojolicious-Plugin-CHI
-Version: 0.07
+Version: 0.09
Release: 0
%define cpan_name Mojolicious-Plugin-CHI
Summary: Use CHI caches in Mojolicious
@@ -30,10 +30,11 @@
BuildRequires: perl
BuildRequires: perl-macros
BuildRequires: perl(CHI)
-BuildRequires: perl(Mojolicious) >= 3.43
+BuildRequires: perl(Mojolicious) >= 4.77
BuildRequires: perl(Test::More)
+BuildRequires: perl(Test::Output) >= 1.0
Requires: perl(CHI)
-Requires: perl(Mojolicious) >= 3.43
+Requires: perl(Mojolicious) >= 4.77
%{perl_requires}
%description
++++++ Mojolicious-Plugin-CHI-0.07.tar.gz -> Mojolicious-Plugin-CHI-0.09.tar.gz
++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/Changes
new/Mojolicious-Plugin-CHI-0.09/Changes
--- old/Mojolicious-Plugin-CHI-0.07/Changes 2014-04-01 17:37:46.000000000
+0200
+++ new/Mojolicious-Plugin-CHI-0.09/Changes 2014-04-20 20:27:56.000000000
+0200
@@ -1,3 +1,11 @@
+0.09 2014-04-20
+ - Bugfix test suite.
+
+0.08 2014-04-17
+ - Logging now defaults to application log.
+ - Update requirements.
+ - Added commands.
+
0.07 2014-04-01
- Update year.
- Documentation tweaks on CHI.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/MANIFEST
new/Mojolicious-Plugin-CHI-0.09/MANIFEST
--- old/Mojolicious-Plugin-CHI-0.07/MANIFEST 2014-04-01 17:39:15.000000000
+0200
+++ new/Mojolicious-Plugin-CHI-0.09/MANIFEST 2014-04-20 20:31:41.000000000
+0200
@@ -1,6 +1,9 @@
lib/Mojolicious/Plugin/CHI.pm
+lib/Mojolicious/Plugin/CHI/chi.pm
t/CHI.t
t/CHI-File.t
+t/CHI-Log.t
+t/CHI-Command.t
t/CHI-NoIOLoop.t
Changes
MANIFEST
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/META.json
new/Mojolicious-Plugin-CHI-0.09/META.json
--- old/Mojolicious-Plugin-CHI-0.07/META.json 2014-04-01 17:39:15.000000000
+0200
+++ new/Mojolicious-Plugin-CHI-0.09/META.json 2014-04-20 20:31:41.000000000
+0200
@@ -22,7 +22,8 @@
"prereqs" : {
"build" : {
"requires" : {
- "Test::More" : "0"
+ "Test::More" : "0",
+ "Test::Output" : "1"
}
},
"configure" : {
@@ -33,7 +34,7 @@
"runtime" : {
"requires" : {
"CHI" : "0",
- "Mojolicious" : "3.43",
+ "Mojolicious" : "4.77",
"perl" : "5.010001"
}
}
@@ -47,5 +48,5 @@
"url" : "https://github.com/Akron/Mojolicious-Plugin-CHI"
}
},
- "version" : "0.07"
+ "version" : "0.09"
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/META.yml
new/Mojolicious-Plugin-CHI-0.09/META.yml
--- old/Mojolicious-Plugin-CHI-0.07/META.yml 2014-04-01 17:39:15.000000000
+0200
+++ new/Mojolicious-Plugin-CHI-0.09/META.yml 2014-04-20 20:31:41.000000000
+0200
@@ -4,6 +4,7 @@
- 'Nils Diewald'
build_requires:
Test::More: '0'
+ Test::Output: '1'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
@@ -19,9 +20,9 @@
- inc
requires:
CHI: '0'
- Mojolicious: '3.43'
+ Mojolicious: '4.77'
perl: '5.010001'
resources:
license: http://www.opensource.org/licenses/artistic-license-2.0
repository: https://github.com/Akron/Mojolicious-Plugin-CHI
-version: '0.07'
+version: '0.09'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/Makefile.PL
new/Mojolicious-Plugin-CHI-0.09/Makefile.PL
--- old/Mojolicious-Plugin-CHI-0.07/Makefile.PL 2014-03-30 15:57:59.000000000
+0200
+++ new/Mojolicious-Plugin-CHI-0.09/Makefile.PL 2014-04-17 19:37:13.000000000
+0200
@@ -10,10 +10,11 @@
ABSTRACT => 'Use CHI Caches in Mojolicious',
AUTHOR => 'Nils Diewald',
BUILD_REQUIRES => {
- 'Test::More' => 0
+ 'Test::More' => 0,
+ 'Test::Output' => 1.0
},
PREREQ_PM => {
- 'Mojolicious' => 3.43,
+ 'Mojolicious' => 4.77,
'CHI' => 0
},
LICENSE => 'artistic_2',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/Mojolicious-Plugin-CHI-0.07/lib/Mojolicious/Plugin/CHI/chi.pm
new/Mojolicious-Plugin-CHI-0.09/lib/Mojolicious/Plugin/CHI/chi.pm
--- old/Mojolicious-Plugin-CHI-0.07/lib/Mojolicious/Plugin/CHI/chi.pm
1970-01-01 01:00:00.000000000 +0100
+++ new/Mojolicious-Plugin-CHI-0.09/lib/Mojolicious/Plugin/CHI/chi.pm
2014-04-17 17:39:45.000000000 +0200
@@ -0,0 +1,205 @@
+package Mojolicious::Plugin::CHI::chi;
+use Mojo::Base 'Mojolicious::Command';
+use Mojo::Util 'tablify';
+
+use Getopt::Long qw/GetOptions :config no_auto_abbrev no_ignore_case/;
+
+has description => 'Interact with CHI caches.';
+has usage => sub { shift->extract_usage };
+
+# Run chi
+sub run {
+ my $self = shift;
+
+ my $command = shift;
+
+ print $self->usage and return unless $command;
+
+ # Get the application
+ my $app = $self->app;
+ my $log = $app->log;
+
+ # List all associated caches
+ if ($command eq 'list') {
+ my $caches = $app->chi_handles;
+ my @list;
+ foreach (sort { lc($a) cmp lc($b) } keys %$caches) {
+ push(@list, [$_, ($caches->{$_}->short_driver_name || '[UNKNOWN]')]);
+ };
+ print tablify \@list;
+ return 1;
+ }
+
+ # Purge or clear a cache
+ elsif ($command eq 'purge' || $command eq 'clear') {
+ my $cache = shift || 'default';
+
+ my $chi = $app->chi($cache);
+
+ # Do not modify non-persistant in-process caches!
+ if ($chi->short_driver_name =~ /^(?:Raw)?Memory$/) {
+ $log->warn("You are trying to $command a ".
+ $chi->short_driver_name .
+ '-Cache');
+ };
+
+ $chi->$command();
+
+ # Purge or clear cache
+ print qq{Cache "$cache" was } . $command .
+ ($command eq 'clear' ? 'ed' : 'd') . ".\n\n";
+
+ return 1;
+ }
+
+ # Remove or expire a key
+ elsif ($command eq 'remove' || $command eq 'expire') {
+ my $key = pop(@_);
+ my $cache = shift || 'default';
+
+ if ($key) {
+
+ my $chi = $app->chi($cache);
+
+ # Do not modify non-persistant in-process caches!
+ if ($chi->short_driver_name =~ /^(?:Raw)?Memory$/) {
+ $log->warn("You are trying to $command " .
+ 'a key from a '.
+ $chi->short_driver_name .
+ '-Cache');
+ };
+
+ # Remove or expire key
+ if ($chi->$command($key)) {
+ print qq{Key "$key" from cache "$cache" was } . $command . "d.\n\n";
+ }
+
+ # Not successful
+ else {
+ print 'Unable to ' . $command .
+ qq{ key "$key" from cache "$cache".\n\n};
+ };
+
+ return 1;
+ };
+ };
+
+ # Unknown command
+ print $self->usage and return;
+};
+
+
+1;
+
+
+__END__
+
+=pod
+
+=encoding utf8
+
+=head1 NAME
+
+Mojolicious::Plugin::CHI::chi - Interact with CHI caches
+
+
+=head1 SYNOPSIS
+
+ usage: perl app.pl chi <command> [cache] [key]
+
+ perl app.pl chi list
+ perl app.pl chi purge
+ perl app.pl chi clear mycache
+ perl app.pl chi expire mykey
+ perl app.pl chi remove mycache mykey
+
+ Interact with CHI caches associated with your application.
+ Valid commands include:
+
+ list
+ List all chi caches associated with your application.
+
+ purge [cache]
+ Remove all expired entries from the cache namespace.
+
+ clear [cache]
+ Remove all entries from the cache namespace.
+
+ expire [cache] [key]
+ Set the expiration date of a key to the past.
+ This does not necessarily delete the data.
+
+ remove [cache] [key]
+ Remove a key from the cache
+
+ "purge" and "expire" expect a cache namespace as their only argument.
+ If no cache namespace is given, the default cache namespace is assumed.
+
+ "expire" and "remove" expect a cache namespace and a key name as their
+ arguments. If no cache namespace is given, the default cache
+ namespace is assumed.
+
+
+=head1 DESCRIPTION
+
+L<Mojolicious::Plugin::CHI::chi> helps you to interact with
+caches associated with L<Mojolicious::Plugin::CHI>.
+
+
+=head1 ATTRIBUTES
+
+L<Mojolicious::Plugin::CHI::chi> inherits all attributes
+from L<Mojolicious::Command> and implements the following new ones.
+
+
+=head2 description
+
+ my $description = $chi->description;
+ $chi = $chi->description('Foo!');
+
+Short description of this command, used for the command list.
+
+
+=head2 usage
+
+ my $usage = $chi->usage;
+ $chi = $chi->usage('Foo!');
+
+Usage information for this command, used for the help screen.
+
+
+=head1 METHODS
+
+L<Mojolicious::Plugin::CHI::chi> inherits all methods from
+L<Mojolicious::Command> and implements the following new ones.
+
+
+=head2 run
+
+ $chi->run;
+
+Run this command.
+
+
+=head1 DEPENDENCIES
+
+L<Mojolicious>,
+L<CHI>.
+
+
+=head1 AVAILABILITY
+
+ https://github.com/Akron/Mojolicious-Plugin-CHI
+
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2013-2014, L<Nils Diewald||http://nils-diewald.de>.
+
+This program is free software, you can redistribute it
+and/or modify it under the same terms as Perl.
+
+The documentation is based on L<Mojolicious::Command::eval>,
+written by Sebastian Riedel.
+
+=cut
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/Mojolicious-Plugin-CHI-0.07/lib/Mojolicious/Plugin/CHI.pm
new/Mojolicious-Plugin-CHI-0.09/lib/Mojolicious/Plugin/CHI.pm
--- old/Mojolicious-Plugin-CHI-0.07/lib/Mojolicious/Plugin/CHI.pm
2014-04-01 17:32:06.000000000 +0200
+++ new/Mojolicious-Plugin-CHI-0.09/lib/Mojolicious/Plugin/CHI.pm
2014-04-20 20:23:47.000000000 +0200
@@ -1,8 +1,9 @@
package Mojolicious::Plugin::CHI;
use Mojo::Base 'Mojolicious::Plugin';
+use Scalar::Util 'weaken';
use CHI;
-our $VERSION = '0.07';
+our $VERSION = '0.09';
# Register Plugin
sub register {
@@ -14,18 +15,41 @@
};
# Hash of cache handles
- my $caches = {};
+ my $caches;
+
+ # Add 'chi_handles' attribute
+ # Necessary for multiple cache registrations
+ unless ($mojo->can('chi_handles')) {
+ $mojo->attr(
+ chi_handles => sub {
+ return ($caches //= {});
+ }
+ );
+ }
+
+ # Get caches from application
+ else {
+ $caches = $mojo->chi_handles;
+ };
+
# Support namespaces
my $ns = delete $param->{namespaces} // 1;
+ # Create log callback for CHI Logging
+ my $log = $mojo->log;
+ weaken $log;
+ my $log_ref = sub {
+ $log->warn( shift ) if defined $log;
+ };
+
# Loop through all caches
foreach my $name (keys %$param) {
my $cache_param = $param->{$name};
# Already exists
if (exists $caches->{$name}) {
- $mojo->log->warn("Multiple attempts to establish cache '$name'");
+ $mojo->log->warn(qq{Multiple attempts to establish cache "$name"});
next;
};
@@ -35,17 +59,25 @@
};
# Get CHI handle
- my $cache = CHI->new( %$cache_param );
+ my $cache = CHI->new(
+
+ # Set logging routines
+ on_get_error => $log_ref,
+ on_set_error => $log_ref,
+
+ %$cache_param
+ );
# No succesful creation
- unless ($cache) {
- $mojo->log->warn("Unable to create cache handle '$name'");
- };
+ $mojo->log->warn(qq{Unable to create cache handle "$name"}) unless $cache;
# Store CHI handle
$caches->{$name} = $cache;
};
+ # Add 'chi' command
+ push @{$mojo->commands->namespaces}, __PACKAGE__;
+
# Add 'chi' helper
$mojo->helper(
@@ -56,7 +88,7 @@
my $cache = $caches->{$name};
# Cache unknown
- $mojo->log->warn("Unknown cache handle '$name'") unless $cache;
+ $c->app->log->warn(qq{Unknown cache handle "$name"}) unless $cache;
# Return cache
return $cache;
@@ -149,14 +181,15 @@
Called when registering the plugin.
On creation, the plugin accepts a hash of cache names
associated with L<CHI> objects.
-
All cache handles are qualified L<CHI> namespaces.
You can omit this mapping by passing a C<namespaces>
parameter with a C<false> value.
-
The handles have to be unique, i.e.
you can't have multiple different C<default> caches in mounted
applications using L<Mojolicious::Plugin::Mount>.
+Logging defaults to the application log, but can be
+overridden using L<on_get_error|CHI/CONSTRUCTOR> and
+L<on_set_error|CHI/CONSTRUCTOR>.
All parameters can be set either on registration or
as part of the configuration file with the key C<CHI>.
@@ -177,6 +210,51 @@
C<default> is assumed.
+=head1 COMMANDS
+
+The following commands are available
+when the plugin is registered.
+
+=head2 chi list
+
+ perl app.pl chi list
+
+List all CHI caches associated with your application.
+
+
+=head2 chi purge
+
+ perl app.pl chi purge mycache
+
+Remove all expired entries from the cache namespace.
+
+
+=head2 chi clear
+
+ perl app.pl chi clear mycache
+
+Remove all entries from the cache namespace.
+
+
+=head2 chi expire
+
+ perl app.pl chi expire mykey
+ perl app.pl chi expire mycache mykey
+
+Set the expiration date of a key to the past.
+This does not necessarily delete the data,
+but makes it unavailable using C<get>.
+
+
+=head2 chi remove
+
+ perl app.pl chi remove mykey
+ perl app.pl chi remove mycache mykey
+
+Remove a key from the cache.
+
+
+
=head1 DEPENDENCIES
L<Mojolicious>,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/t/CHI-Command.t
new/Mojolicious-Plugin-CHI-0.09/t/CHI-Command.t
--- old/Mojolicious-Plugin-CHI-0.07/t/CHI-Command.t 1970-01-01
01:00:00.000000000 +0100
+++ new/Mojolicious-Plugin-CHI-0.09/t/CHI-Command.t 2014-04-18
15:03:26.000000000 +0200
@@ -0,0 +1,208 @@
+#!/usr/bin/env perl
+use Mojolicious::Lite;
+use Test::More;
+use Test::Mojo;
+use Test::Output;
+use File::Temp qw/:POSIX tempdir/;
+
+use lib 'lib';
+use lib '../lib';
+
+use_ok 'Mojolicious::Plugin::CHI';
+
+my $t = Test::Mojo->new;
+my $app = $t->app;
+
+my $hash1 = {};
+my $hash2 = {};
+
+$app->plugin(Config => {
+ default => {
+ CHI => {
+ first => {
+ driver => 'Memory',
+ datastore => $hash1
+ },
+ MySecondCache => {
+ driver => 'Memory',
+ datastore => $hash2
+ }
+ }
+ }
+});
+
+$app->plugin('CHI');
+
+{
+ no warnings;
+ $Time::Duration::MILLISECOND = 1;
+};
+
+use_ok('Mojolicious::Plugin::CHI::chi');
+
+my $chi = Mojolicious::Plugin::CHI::chi->new;
+$chi->app($app);
+
+is($chi->description, "Interact with CHI caches.", 'Description line');
+
+stdout_like(
+ sub { $chi->run },
+ qr/perl app\.pl chi clear mycache/,
+ 'Show option list'
+);
+
+my $usage = $chi->usage;
+
+stdout_is(
+ sub { $chi->run },
+ $usage,
+ 'Show option list'
+);
+
+stdout_like(
+ sub { $chi->run('list') },
+ qr/first\s+Memory\s+MySecondCache\s+Memory/,
+ 'Show driver list'
+);
+
+my $path = tempdir(CLEANUP => 1);
+$app->plugin(CHI => {
+ MyFlatFile => {
+ driver => 'File',
+ root_dir => $path,
+ # This may be a mysterious CHI bug
+ max_key_length => 200
+ }
+});
+
+stdout_like(
+ sub { $chi->run('list') },
+ qr/first\s+Memory\s+MyFlatFile\s+File\s+MySecondCache\s+Memory/,
+ 'Show driver list'
+);
+
+my $flat_file = $app->chi('MyFlatFile');
+ok($flat_file->set(key_1 => 'value_1', { expires_in => '5m' }), 'Set key');
+is($flat_file->get('key_1'), 'value_1', 'Get key');
+ok($flat_file->set(key_2 => 'value_2' => { expires_in => 0.1 }), 'Set key');
+
+select(undef, undef, undef, 0.2);
+
+ok(!$flat_file->get('key_2'), 'Get key impossible');
+ok($flat_file->get_object('key_2')->is_expired, 'Key is expired');
+
+stdout_is(
+ sub { $chi->run('purge', 'MyFlatFile') },
+ "Cache \"MyFlatFile\" was purged.\n\n",
+ 'Purge cache'
+);
+
+ok(!$flat_file->get_object('key_2'), 'Key is removed');
+is($flat_file->get('key_1'), 'value_1', 'Get key');
+
+stdout_is(
+ sub { $chi->run('clear', 'MyFlatFile') },
+ "Cache \"MyFlatFile\" was cleared.\n\n",
+ 'Clear cache'
+);
+
+ok(!$flat_file->get_object('key_1'), 'Key is removed');
+
+ok($flat_file->set(key_3 => 'value_3'), 'Set key');
+ok($flat_file->set(key_4 => 'value_4'), 'Set key');
+is($flat_file->get('key_3'), 'value_3', 'Get key');
+is($flat_file->get('key_4'), 'value_4', 'Get key');
+
+stdout_is(
+ sub { $chi->run('remove', 'MyFlatFile', 'key_3') },
+ "Key \"key_3\" from cache \"MyFlatFile\" was removed.\n\n",
+ 'Remove key'
+);
+ok(!$flat_file->get('key_3'), 'Get key');
+
+is($flat_file->get('key_4'), 'value_4', 'Get key');
+
+stdout_is(
+ sub { $chi->run('expire', 'MyFlatFile', 'key_4') },
+ "Key \"key_4\" from cache \"MyFlatFile\" was expired.\n\n",
+ 'Expire key'
+);
+
+ok(!$flat_file->get('key_4'), 'Unable to get key');
+
+ok($flat_file->get_object('key_4')->is_expired, 'Key is expired');
+
+stdout_is(
+ sub { $chi->run('remove', 'MyFlatFile', 'key_3') },
+ "Unable to remove key \"key_3\" from cache \"MyFlatFile\".\n\n",
+ 'Expire key'
+);
+
+# Again with default
+
+$path = tempdir(CLEANUP => 1);
+$app->plugin(CHI => {
+ default => {
+ driver => 'File',
+ root_dir => $path
+ }
+});
+
+my $cache = $app->chi;
+ok($cache->set(key_1 => 'value_1', { expires_in => '5m' }), 'Set key');
+is($cache->get('key_1'), 'value_1', 'Get key');
+ok($cache->set(key_2 => 'value_2' => { expires_in => 0.1 }), 'Set key');
+
+select(undef, undef, undef, 0.2);
+
+ok(!$cache->get('key_2'), 'Get key impossible');
+ok($cache->get_object('key_2')->is_expired, 'Key is expired');
+
+stdout_is(
+ sub { $chi->run('purge') },
+ qq{Cache "default" was purged.\n\n},
+ 'Purge cache'
+);
+
+ok(!$cache->get_object('key_2'), 'Key is removed');
+is($cache->get('key_1'), 'value_1', 'Get key');
+
+stdout_is(
+ sub { $chi->run('clear') },
+ qq{Cache "default" was cleared.\n\n},
+ 'Clear cache'
+);
+
+ok(!$cache->get_object('key_1'), 'Key is removed');
+
+ok($cache->set(key_3 => 'value_3'), 'Set key');
+ok($cache->set(key_4 => 'value_4'), 'Set key');
+is($cache->get('key_3'), 'value_3', 'Get key');
+is($cache->get('key_4'), 'value_4', 'Get key');
+
+stdout_is(
+ sub { $chi->run('remove', 'key_3') },
+ qq{Key "key_3" from cache "default" was removed.\n\n},
+ 'Remove key'
+);
+ok(!$cache->get('key_3'), 'Get key');
+
+is($cache->get('key_4'), 'value_4', 'Get key');
+
+stdout_is(
+ sub { $chi->run('expire', 'key_4') },
+ qq{Key "key_4" from cache "default" was expired.\n\n},
+ 'Expire key'
+);
+
+ok(!$cache->get('key_4'), 'Unable to get key');
+
+ok($cache->get_object('key_4')->is_expired, 'Key is expired');
+
+stdout_is(
+ sub { $chi->run('remove', 'key_3') },
+ qq{Unable to remove key "key_3" from cache "default".\n\n},
+ 'Expire key'
+);
+
+done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/t/CHI-File.t
new/Mojolicious-Plugin-CHI-0.09/t/CHI-File.t
--- old/Mojolicious-Plugin-CHI-0.07/t/CHI-File.t 2014-04-01
17:33:55.000000000 +0200
+++ new/Mojolicious-Plugin-CHI-0.09/t/CHI-File.t 2014-04-17
15:04:09.000000000 +0200
@@ -36,8 +36,7 @@
my @test = readdir(D);
closedir(D);
-ok('MyCache2' ~~ \@test, 'Namespace option valid');
-
+ok(join(',', @test) =~ m/MyCache2/, 'Namespace option valid');
# Test with new namespace default
@@ -50,7 +49,7 @@
$path = tempdir(CLEANUP => 1);
$app->plugin(CHI => {
- MyCache2 => {
+ MyCache3 => {
driver => 'File',
root_dir => $path
}
@@ -58,7 +57,7 @@
Mojo::IOLoop->start;
-$my_cache = $c->chi('MyCache2');
+$my_cache = $c->chi('MyCache3');
ok($my_cache, 'CHI handle');
ok($my_cache->set(key_1 => 'Wert 1'), 'Wert 1');
is($my_cache->get('key_1'), 'Wert 1', 'Wert 1');
@@ -73,7 +72,7 @@
fail('Unable to read cache dir');
};
-ok('MyCache2' ~~ \@test, 'Namespace option valid');
+ok(join(',', @test) =~ m/MyCache3/, 'Namespace option valid');
# Test with off namespace
@@ -86,7 +85,7 @@
$path = tempdir(CLEANUP => 1);
$app->plugin(CHI => {
- MyCache2 => {
+ MyCache4 => {
driver => 'File',
root_dir => $path
},
@@ -95,7 +94,7 @@
Mojo::IOLoop->start;
-$my_cache = $c->chi('MyCache2');
+$my_cache = $c->chi('MyCache4');
ok($my_cache, 'CHI handle');
ok($my_cache->set(key_1 => 'Wert 1'), 'Wert 1');
is($my_cache->get('key_1'), 'Wert 1', 'Wert 1');
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Mojolicious-Plugin-CHI-0.07/t/CHI-Log.t
new/Mojolicious-Plugin-CHI-0.09/t/CHI-Log.t
--- old/Mojolicious-Plugin-CHI-0.07/t/CHI-Log.t 1970-01-01 01:00:00.000000000
+0100
+++ new/Mojolicious-Plugin-CHI-0.09/t/CHI-Log.t 2014-04-17 14:40:17.000000000
+0200
@@ -0,0 +1,70 @@
+#!/usr/bin/env perl
+use Mojolicious::Lite;
+use Test::More;
+use Test::Mojo;
+use File::Temp qw/:POSIX tempdir/;
+use File::Path qw/remove_tree/;
+
+use lib 'lib';
+use lib '../lib';
+
+use_ok 'Mojolicious::Plugin::CHI';
+
+my $t = Test::Mojo->new;
+my $app = $t->app;
+
+my $c = Mojolicious::Controller->new;
+$c->app($app);
+
+my $path = tempdir(CLEANUP => 1);
+
+$app->plugin(CHI => {
+ default => {
+ driver => 'File',
+ root_dir => $path
+ }
+});
+
+Mojo::IOLoop->start;
+
+my $string = '';
+$app->log->on(
+ message => sub {
+ shift;
+ $string .= join '---', @_;
+ });
+
+$app->log->debug('test');
+is($string, 'debug---test', 'Check log');
+
+ok($c->chi->set('key_1' => 'value_1'), 'Set key');
+is($c->chi->get('key_1'), 'value_1', 'Get key');
+
+opendir(D, $path);
+my @test = readdir(D);
+closedir(D);
+
+ok(join(',', @test) =~ m/Default/, 'Namespace option valid');
+
+remove_tree($path);
+
+ok(!-d $path, 'Directory does not exist');
+
+# Cache is automatically recreated
+ok($c->chi->set('key_2' => 'value_2'), 'Set key');
+is($c->chi->get('key_2'), 'value_2', 'Get key');
+
+ok(-d $path, 'Directory does not exist');
+
+remove_tree($path . '/Default');
+
+ok(open(my $f, '>' . $path . '/Default'), 'Touch file');
+
+# Cache is automatically recreated
+$string = '';
+ok($c->chi->set('key_3' => 'value_3'), 'Set key');
+like($string, qr/^warn---error during cache set/, 'Set error log');
+
+ok(!$c->chi->get('key_3'), 'Get key');
+
+done_testing;
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]