AnyEvent-Redis-0.24/0000755000175000001440000000000012062127520012716 5ustar dglusersAnyEvent-Redis-0.24/t/0000755000175000001440000000000012062127520013161 5ustar dglusersAnyEvent-Redis-0.24/t/Redis.pm0000644000175000001440000000221512062126625014572 0ustar dgluserspackage t::Redis; use strict; use Test::TCP; use Test::More; use AnyEvent::Redis; use FindBin; use base qw(Exporter); our @EXPORT = qw(test_redis); sub test_redis(&;$) { my $cb = shift; my $args = shift; chomp(my $redis_server = `which redis-server`); unless ($redis_server && -e $redis_server && -x _) { plan skip_all => 'redis-server not found in your PATH'; } test_tcp server => sub { my $port = shift; rewrite_redis_conf($port); exec "redis-server", "t/redis.conf"; }, client => sub { my $port = shift; my $r = AnyEvent::Redis->new( host => "127.0.0.1", port => $port, ref $args ? %$args : () ); $cb->($r, $port); }; } sub rewrite_redis_conf { my $port = shift; my $dir = $FindBin::Bin; open my $in, "<", "t/redis.conf.base" or die $!; open my $out, ">", "t/redis.conf" or die $!; while (<$in>) { s/__PORT__/$port/; s/__DIR__/$dir/; print $out $_; } } END { unlink $_ for "t/redis.conf", "t/dump.rdb" } 1; AnyEvent-Redis-0.24/t/leak.t0000644000175000001440000000174211735272724014303 0ustar dglusersuse strict; use Test::More; use t::Redis; BEGIN { eval q{use Test::LeakTrace}; plan skip_all => "Test::LeakTrace required" if $@; } test_redis { my $r = shift; my $port = shift; $r->all_cv->begin(sub { $_[0]->send }); if($r->info->recv->{redis_version} ge "1.3.0") { # Set values used later no_leaks_ok { $r->multi; $r->set("foo$_" => "bar$_") for 1 .. 10; $r->exec->recv; } "multi/set"; # Check values no_leaks_ok { $r->multi; $r->mget(map { "foo$_" } 1 .. 5); $r->mget(map { "foo$_" } 6 .. 10); my $res = $r->exec->recv; } "multi/mget"; # Reproduce github issue 6: # http://github.com/miyagawa/AnyEvent-Redis/issues/issue/6 no_leaks_ok { $r->blpop('a' .. 'z', 1)->recv; } "blpop"; $r->all_cv->end; $r->all_cv->recv; done_testing; } else { plan skip_all => "No support for MULTI in this server version"; } }; AnyEvent-Redis-0.24/t/reconnect.t0000644000175000001440000000075512062126625015342 0ustar dglusersuse strict; use Test::More; use t::Redis; test_redis { my ($r, $port) = @_; # make a new redis object using wrong port my $redis = AnyEvent::Redis->new(host => "127.0.0.1", port => Test::TCP::empty_port()); # should fail eval { $redis->info->recv; }; ok $@, "got exception from error"; # fix the port and try again $redis->{port} = $port; my $info = $redis->info->recv; ok $info->{redis_version}, "got response after reconnect"; }; done_testing; AnyEvent-Redis-0.24/t/pubsub.t0000644000175000001440000000320312036534601014647 0ustar dglusersuse strict; use Test::More; use t::Redis; test_redis { my $sub = shift; my $port = shift; my $info = $sub->info->recv; if($info->{redis_version} lt "1.3.10") { plan skip_all => "No PUBLISH/SUBSCRIBE support in this Redis version"; } my $pub = AnyEvent::Redis->new(host => "127.0.0.1", port => $port); # $pub is for publishing # $sub is for subscribing my $x = 0; my $expected_x = 0; my $count = 0; my $expected_count = 10; $sub->all_cv->begin; $sub->subscribe("test.1", sub { my($message, $chan) = @_; $x += $message; if(++$count == $expected_count) { $sub->unsubscribe("test.1"); is $x, $expected_x, "Messages received, values as expected"; } }); # Pattern subscription my $y = 0; my $expected_y = 0; my $count2 = 0; $sub->psubscribe("testp.*", sub { my($message, $chan) = @_; $y += $message; if(++$count2 == $expected_count) { $sub->punsubscribe("testp.*"); is $y, $expected_y, "Messages received, values as expected"; } }); for(1 .. $expected_count) { my $cv = $pub->publish("test.1" => $_); $expected_x += $_; # Need to be sure a client has subscribed $expected_x = 0, redo unless $cv->recv; } for(1 .. $expected_count) { my $cv = $pub->publish("testp.$_" => $_); $expected_y += $_; # Need to be sure a client has subscribed $expected_y = 0, redo unless $cv->recv; } $sub->all_cv->end; done_testing; }; AnyEvent-Redis-0.24/t/utf8.t0000644000175000001440000000244211735272724014253 0ustar dglusersuse strict; use Test::More; use t::Redis; test_redis { my $r = shift; $r->all_cv->begin(sub { $_[0]->send }); my $info = $r->info->recv; is ref $info, 'HASH'; ok $info->{redis_version}; { use utf8; my $key = "ロジ プロセスド"; my $val = "लचकनहि"; $r->set($key => $val, sub { pass "SET literal UTF-8 key/value" }); $r->get($key, sub { is $_[0], $val, "GET literal UTF-8 key/value"; }); } my $utf8_key = "\x{a3}\x{acd}"; my $utf8_val = "\x{90e}\x{60a}"; $r->set($utf8_key => $utf8_val, sub { pass "SET escaped UTF-8 key/value" }); $r->get($utf8_key, sub { is $_[0], $utf8_val, "GET escaped UTF-8 key/value"; }); my $latin1_key = "V\x{f6}gel"; my $latin1_val = "Gr\x{fc}n"; $r->set($latin1_key => $latin1_val, sub { pass "SET escaped Latin-1 key/value" }); $r->get($latin1_key, sub { is $_[0], $latin1_val, "GET escaped Latin-1 key/value"; }); $r->all_cv->end; $r->all_cv->recv; eval { AnyEvent::Redis->new(encoding => "invalid") }; like $@, qr/Encoding "invalid" not found/; } # Extra args for the constructor { encoding => "utf8" }; done_testing; # vim:fileencoding=utf8 AnyEvent-Redis-0.24/t/multi.t0000644000175000001440000000200312036524033014474 0ustar dglusersuse strict; use Test::More; use t::Redis; test_redis { my $r = shift; $r->all_cv->begin(sub { $_[0]->send }); if($r->info->recv->{redis_version} ge "1.3.0") { # Multi/exec with no commands $r->multi->recv; $r->exec(sub { ok 0 == @{$_[0]}; }); # Simple multi/exec my $nsets = 0; $r->multi; $r->set("foo$_" => "bar$_", sub { ++$nsets }) for 1 .. 10; $r->exec(sub { ok 10 == grep /^OK$/, @{$_[0]}; ok 10 == $nsets; }); # Complex multi/exec my $y; my $get5 = sub { ok 5 == grep { $y++; /^bar$y$/ } @{$_[0]} }; $r->multi; $r->mget((map { "foo$_" } 1 .. 5), $get5); $r->mget((map { "foo$_" } 6 .. 10), $get5); $r->exec(sub { my $x = 0; ok 10 == grep { $x++; /^bar$x$/ } map { @$_ } @{$_[0]}; }); $r->all_cv->end; $r->all_cv->recv; done_testing; } else { plan skip_all => "No support for MULTI in this server version"; } }; AnyEvent-Redis-0.24/t/client.t0000644000175000001440000000437612016740105014635 0ustar dglusersuse strict; use Test::More; use t::Redis; test_redis { my $r = shift; $r->all_cv->begin(sub { $_[0]->send }); my $info = $r->info->recv; is ref $info, 'HASH'; ok $info->{redis_version}; $r->set("foo", "bar", sub { pass "SET foo" }); $r->get("foo", sub { is $_[0], "bar" }); $r->lpush("list", "bar"); $r->lpush("list", "baz"); is $r->lpop("list")->recv, 'baz'; is $r->lpop("list")->recv, 'bar'; $r->set("prefix.bar", "test", sub { $r->get("prefix.bar", sub { is $_[0], "test" }) }); $r->set("prefix.baz", "test"); $r->mget( "prefix.bar", "prefix.baz", "foo", sub { my $res = shift; is $res->[0], "test"; is $res->[2], "bar"; } ); $r->mget( 1, 2, 3, sub { my $res = shift; map { ok !$_ } @$res; } ); $r->mget( 1, "prefix.baz", "barbaz", sub { my $res = shift; ok !$res->[0]; is $res->[1], "test"; ok !$res->[2]; } ); if ($info->{redis_version} =~ /^2/) { $r->hset("hash", "foo", "bar", sub { is $_[0], 1 }); $r->hset("hash", "baz", "foo"); $r->hget("hash", "foo", sub { is $_[0], "bar" }); $r->hmget("hash", "foo", "baz", sub { my $res = shift; is $res->[0], "bar"; is $res->[1], "foo" }); $r->hdel("hash", "foo", sub { is $_[0], 1 }); $r->hmset("hash", "foo", 1, "bar", 2, "baz", 3, sub { my $res = shift; ok $res }); $r->hincrby("hash", "foo", 2, sub { my $res = shift; is $res, 3 }); $r->hkeys("hash", sub {my $res = shift; is scalar @$res, 3;}); $r->hvals("hash", sub {my $res = shift; is scalar @$res, 3;}); $r->hgetall("hash", sub {my $res = shift; is scalar @$res, 6;}); for (qw/foo bar baz/) { $r->hdel("hash", $_); } } $r->keys('prefix.*', sub { my $keys = shift; is ref $keys, 'ARRAY'; is @$keys, 2 }); my $cv = $r->get("nonx"); is $cv->recv, undef; my $err; $r->{on_error} = sub { $err = shift }; $r->bogus("foo", sub { }); $r->all_cv->end; $r->all_cv->recv; like $err, qr/ERR unknown command/; }; done_testing; AnyEvent-Redis-0.24/t/lrange.t0000644000175000001440000000376511735272724014646 0ustar dglusersuse strict; use Test::More; use t::Redis; test_redis { my $r = shift; for my $n(1 .. 10) { my $key1 = "lrange_test1_$n"; my $key2 = "lrange_test2_$n"; $r->del($key1); $r->del($key2); for (1 .. 20) { $r->rpush($key1, join "\n", map {"A" x 100} (0 .. 3)); $r->rpush($key2, join "\n", map {"B" x 100} (0 .. 3)); } for (1 .. 20) { $r->rpush($key1, join "\n", map {"C" x 100} (0 .. 3)); $r->rpush($key2, join "\n", map {"D" x 100} (0 .. 3)); } $r->all_cv->begin; $r->lrange($key1, 0, 19, sub { my $value = join "\n", map {"A" x 100} (0 .. 3); is scalar @{$_[0]}, 20, "correct length $key1 0 19"; is $_[0][-1], $value, "correct end value $key1 0 19"; is $_[0][0], $value, "correct start value $key1 0 19"; $r->all_cv->end; }); $r->all_cv->begin; $r->lrange($key2, 0, 19, sub { my $value = join "\n", map {"B" x 100} (0 .. 3); is scalar @{$_[0]}, 20, "correct length $key2 0 19"; is $_[0][-1], $value, "correct end value $key2 0 19"; is $_[0][0], $value, "correct start value $key2 0 19"; $r->all_cv->end; }); $r->all_cv->begin; $r->lrange($key1, 20, 39, sub { my $value = join "\n", map {"C" x 100} (0 .. 3); is scalar @{$_[0]}, 20, "correct length $key1 20 39"; is $_[0][-1], $value, "correct end value $key1 20 39"; is $_[0][0], $value, "correct start value $key1 20 39"; $r->del($key1, sub { $r->all_cv->end }); }); $r->all_cv->begin; $r->lrange($key2, 20, 39, sub { my $value = join "\n", map {"D" x 100} (0 .. 3); is scalar @{$_[0]}, 20, "correct length $key2 20 39"; is $_[0][-1], $value, "correct end value $key2 20 39"; is $_[0][0], $value, "correct start value $key2 20 39"; $r->del($key2, sub { $r->all_cv->end }); }); } $r->all_cv->recv; }; done_testing; AnyEvent-Redis-0.24/t/00_compile.t0000644000175000001440000000011311735272724015305 0ustar dglusersuse strict; use Test::More tests => 1; BEGIN { use_ok 'AnyEvent::Redis' } AnyEvent-Redis-0.24/t/redis.conf.base0000644000175000001440000001077512062126632016064 0ustar dglusers# Redis configuration file example # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize no # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default. # You can specify a custom pid file location here. pidfile /var/run/redis.pid # Accept connections on the specified port, default is 6379 port __PORT__ # If you want you can bind a single interface, if the bind option is not # specified all the interfaces will listen for connections. # # bind 127.0.0.1 # Close the connection after a client is idle for N seconds (0 to disable) timeout 300 # Save the DB on disk: # # save # # Will save the DB if both the given number of seconds and the given # number of write operations against the DB occurred. # # In the example below the behaviour will be to save: # after 900 sec (15 min) if at least 1 key changed # after 300 sec (5 min) if at least 10 keys changed # after 60 sec if at least 10000 keys changed save 900 1 save 300 10 save 60 10000 # The filename where to dump the DB dbfilename dump.rdb # For default save/load DB in/from the working directory # Note that you must specify a directory not a file name. dir __DIR__ # Set server verbosity to 'debug' # it can be one of: # debug (a lot of information, useful for development/testing) # notice (moderately verbose, what you want in production probably) # warning (only very important / critical messages are logged) loglevel debug # Specify the log file name. Also 'stdout' can be used to force # the demon to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null logfile stdout # Set the number of databases. The default database is DB 0, you can select # a different one on a per-connection basis using SELECT where # dbid is a number between 0 and 'databases'-1 databases 16 ################################# REPLICATION ################################# # Master-Slave replication. Use slaveof to make a Redis instance a copy of # another Redis server. Note that the configuration is local to the slave # so for example it is possible to configure the slave to save the DB with a # different interval, or to listen to another port, and so on. # slaveof ################################## SECURITY ################################### # Require clients to issue AUTH before processing any other # commands. This might be useful in environments in which you do not trust # others with access to the host running redis-server. # # This should stay commented out for backward compatibility and because most # people do not need auth (e.g. they run their own servers). # requirepass foobared ################################### LIMITS #################################### # Set the max number of connected clients at the same time. By default there # is no limit, and it's up to the number of file descriptors the Redis process # is able to open. The special value '0' means no limts. # Once the limit is reached Redis will close all the new connections sending # an error 'max number of clients reached'. # maxclients 128 # Don't use more memory than the specified amount of bytes. # When the memory limit is reached Redis will try to remove keys with an # EXPIRE set. It will try to start freeing keys that are going to expire # in little time and preserve keys with a longer time to live. # Redis will also try to remove objects from free lists if possible. # # If all this fails, Redis will start to reply with errors to commands # that will use more memory, like SET, LPUSH, and so on, and will continue # to reply to most read-only commands like GET. # # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a # 'state' server or cache, not as a real DB. When Redis is used as a real # database the memory usage will grow over the weeks, it will be obvious if # it is going to use too much memory in the long run, and you'll have the time # to upgrade. With maxmemory after the limit is reached you'll start to get # errors for write operations, and this may even lead to DB inconsistency. # maxmemory ############################### ADVANCED CONFIG ############################### # Glue small output buffers together in order to send small replies in a # single TCP packet. Uses a bit more CPU but most of the times it is a win # in terms of number of queries per second. Use 'yes' if unsure. ## glueoutputbuf yes AnyEvent-Redis-0.24/inc/0000755000175000001440000000000012062127520013467 5ustar dglusersAnyEvent-Redis-0.24/inc/Module/0000755000175000001440000000000012062127520014714 5ustar dglusersAnyEvent-Redis-0.24/inc/Module/Install.pm0000644000175000001440000003013512062127517016670 0ustar dglusers#line 1 package Module::Install; # For any maintainers: # The load order for Module::Install is a bit magic. # It goes something like this... # # IF ( host has Module::Install installed, creating author mode ) { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install # 3. The installed version of inc::Module::Install loads # 4. inc::Module::Install calls "require Module::Install" # 5. The ./inc/ version of Module::Install loads # } ELSE { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install # 3. The ./inc/ version of Module::Install loads # } use 5.005; use strict 'vars'; use Cwd (); use File::Find (); use File::Path (); use vars qw{$VERSION $MAIN}; BEGIN { # All Module::Install core packages now require synchronised versions. # This will be used to ensure we don't accidentally load old or # different versions of modules. # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. $VERSION = '1.06'; # Storage for the pseudo-singleton $MAIN = undef; *inc::Module::Install::VERSION = *VERSION; @inc::Module::Install::ISA = __PACKAGE__; } sub import { my $class = shift; my $self = $class->new(@_); my $who = $self->_caller; #------------------------------------------------------------- # all of the following checks should be included in import(), # to allow "eval 'require Module::Install; 1' to test # installation of Module::Install. (RT #51267) #------------------------------------------------------------- # Whether or not inc::Module::Install is actually loaded, the # $INC{inc/Module/Install.pm} is what will still get set as long as # the caller loaded module this in the documented manner. # If not set, the caller may NOT have loaded the bundled version, and thus # they may not have a MI version that works with the Makefile.PL. This would # result in false errors or unexpected behaviour. And we don't want that. my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; unless ( $INC{$file} ) { die <<"END_DIE" } Please invoke ${\__PACKAGE__} with: use inc::${\__PACKAGE__}; not: use ${\__PACKAGE__}; END_DIE # This reportedly fixes a rare Win32 UTC file time issue, but # as this is a non-cross-platform XS module not in the core, # we shouldn't really depend on it. See RT #24194 for detail. # (Also, this module only supports Perl 5.6 and above). eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006; # If the script that is loading Module::Install is from the future, # then make will detect this and cause it to re-run over and over # again. This is bad. Rather than taking action to touch it (which # is unreliable on some platforms and requires write permissions) # for now we should catch this and refuse to run. if ( -f $0 ) { my $s = (stat($0))[9]; # If the modification time is only slightly in the future, # sleep briefly to remove the problem. my $a = $s - time; if ( $a > 0 and $a < 5 ) { sleep 5 } # Too far in the future, throw an error. my $t = time; if ( $s > $t ) { die <<"END_DIE" } Your installer $0 has a modification time in the future ($s > $t). This is known to create infinite loops in make. Please correct this, then run $0 again. END_DIE } # Build.PL was formerly supported, but no longer is due to excessive # difficulty in implementing every single feature twice. if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } Module::Install no longer supports Build.PL. It was impossible to maintain duel backends, and has been deprecated. Please remove all Build.PL files and only use the Makefile.PL installer. END_DIE #------------------------------------------------------------- # To save some more typing in Module::Install installers, every... # use inc::Module::Install # ...also acts as an implicit use strict. $^H |= strict::bits(qw(refs subs vars)); #------------------------------------------------------------- unless ( -f $self->{file} ) { foreach my $key (keys %INC) { delete $INC{$key} if $key =~ /Module\/Install/; } local $^W; require "$self->{path}/$self->{dispatch}.pm"; File::Path::mkpath("$self->{prefix}/$self->{author}"); $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); $self->{admin}->init; @_ = ($class, _self => $self); goto &{"$self->{name}::import"}; } local $^W; *{"${who}::AUTOLOAD"} = $self->autoload; $self->preload; # Unregister loader and worker packages so subdirs can use them again delete $INC{'inc/Module/Install.pm'}; delete $INC{'Module/Install.pm'}; # Save to the singleton $MAIN = $self; return 1; } sub autoload { my $self = shift; my $who = $self->_caller; my $cwd = Cwd::cwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::cwd(); if ( my $code = $sym->{$pwd} ) { # Delegate back to parent dirs goto &$code unless $cwd eq $pwd; } unless ($$sym =~ s/([^:]+)$//) { # XXX: it looks like we can't retrieve the missing function # via $$sym (usually $main::AUTOLOAD) in this case. # I'm still wondering if we should slurp Makefile.PL to # get some context or not ... my ($package, $file, $line) = caller; die <<"EOT"; Unknown function is found at $file line $line. Execution of $file aborted due to runtime errors. If you're a contributor to a project, you may need to install some Module::Install extensions from CPAN (or other repository). If you're a user of a module, please contact the author. EOT } my $method = $1; if ( uc($method) eq $method ) { # Do nothing return; } elsif ( $method =~ /^_/ and $self->can($method) ) { # Dispatch to the root M:I class return $self->$method(@_); } # Dispatch to the appropriate plugin unshift @_, ( $self, $1 ); goto &{$self->can('call')}; }; } sub preload { my $self = shift; unless ( $self->{extensions} ) { $self->load_extensions( "$self->{prefix}/$self->{path}", $self ); } my @exts = @{$self->{extensions}}; unless ( @exts ) { @exts = $self->{admin}->load_all_extensions; } my %seen; foreach my $obj ( @exts ) { while (my ($method, $glob) = each %{ref($obj) . '::'}) { next unless $obj->can($method); next if $method =~ /^_/; next if $method eq uc($method); $seen{$method}++; } } my $who = $self->_caller; foreach my $name ( sort keys %seen ) { local $^W; *{"${who}::$name"} = sub { ${"${who}::AUTOLOAD"} = "${who}::$name"; goto &{"${who}::AUTOLOAD"}; }; } } sub new { my ($class, %args) = @_; delete $INC{'FindBin.pm'}; { # to suppress the redefine warning local $SIG{__WARN__} = sub {}; require FindBin; } # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; $args{dispatch} ||= 'Admin'; $args{prefix} ||= 'inc'; $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); $args{bundle} ||= 'inc/BUNDLES'; $args{base} ||= $base_path; $class =~ s/^\Q$args{prefix}\E:://; $args{name} ||= $class; $args{version} ||= $class->VERSION; unless ( $args{path} ) { $args{path} = $args{name}; $args{path} =~ s!::!/!g; } $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; $args{wrote} = 0; bless( \%args, $class ); } sub call { my ($self, $method) = @_; my $obj = $self->load($method) or return; splice(@_, 0, 2, $obj); goto &{$obj->can($method)}; } sub load { my ($self, $method) = @_; $self->load_extensions( "$self->{prefix}/$self->{path}", $self ) unless $self->{extensions}; foreach my $obj (@{$self->{extensions}}) { return $obj if $obj->can($method); } my $admin = $self->{admin} or die <<"END_DIE"; The '$method' method does not exist in the '$self->{prefix}' path! Please remove the '$self->{prefix}' directory and run $0 again to load it. END_DIE my $obj = $admin->load($method, 1); push @{$self->{extensions}}, $obj; $obj; } sub load_extensions { my ($self, $path, $top) = @_; my $should_reload = 0; unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) { unshift @INC, $self->{prefix}; $should_reload = 1; } foreach my $rv ( $self->find_extensions($path) ) { my ($file, $pkg) = @{$rv}; next if $self->{pathnames}{$pkg}; local $@; my $new = eval { local $^W; require $file; $pkg->can('new') }; unless ( $new ) { warn $@ if $@; next; } $self->{pathnames}{$pkg} = $should_reload ? delete $INC{$file} : $INC{$file}; push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); } $self->{extensions} ||= []; } sub find_extensions { my ($self, $path) = @_; my @found; File::Find::find( sub { my $file = $File::Find::name; return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; my $subpath = $1; return if lc($subpath) eq lc($self->{dispatch}); $file = "$self->{path}/$subpath.pm"; my $pkg = "$self->{name}::$subpath"; $pkg =~ s!/!::!g; # If we have a mixed-case package name, assume case has been preserved # correctly. Otherwise, root through the file to locate the case-preserved # version of the package name. if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; foreach ( split //, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text next if /^\s*#/; # and comments if ( m/^\s*package\s+($pkg)\s*;/i ) { $pkg = $1; last; } } } push @found, [ $file, $pkg ]; }, $path ) if -d $path; @found; } ##################################################################### # Common Utility Functions sub _caller { my $depth = 0; my $call = caller($depth); while ( $call eq __PACKAGE__ ) { $depth++; $call = caller($depth); } return $call; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _read { local *FH; open( FH, '<', $_[0] ) or die "open($_[0]): $!"; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_NEW sub _read { local *FH; open( FH, "< $_[0]" ) or die "open($_[0]): $!"; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_OLD sub _readperl { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s; $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg; return $string; } sub _readpod { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; return $string if $_[0] =~ /\.pod\z/; $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg; $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg; $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg; $string =~ s/^\n+//s; return $string; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _write { local *FH; open( FH, '>', $_[0] ) or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_NEW sub _write { local *FH; open( FH, "> $_[0]" ) or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_OLD # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). sub _version ($) { my $s = shift || 0; my $d =()= $s =~ /(\.)/g; if ( $d >= 2 ) { # Normalise multipart versions $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg; } $s =~ s/^(\d+)\.?//; my $l = $1 || 0; my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g; $l = $l . '.' . join '', @v if @v; return $l + 0; } sub _cmp ($$) { _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS sub _CLASS ($) { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s ) ? $_[0] : undef; } 1; # Copyright 2008 - 2012 Adam Kennedy. AnyEvent-Redis-0.24/inc/Module/Install/0000755000175000001440000000000012062127520016322 5ustar dglusersAnyEvent-Redis-0.24/inc/Module/Install/Makefile.pm0000644000175000001440000002743712062127517020420 0ustar dglusers#line 1 package Module::Install::Makefile; use strict 'vars'; use ExtUtils::MakeMaker (); use Module::Install::Base (); use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub Makefile { $_[0] } my %seen = (); sub prompt { shift; # Infinite loop protection my @c = caller(); if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; } # In automated testing or non-interactive session, always use defaults if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) { local $ENV{PERL_MM_USE_DEFAULT} = 1; goto &ExtUtils::MakeMaker::prompt; } else { goto &ExtUtils::MakeMaker::prompt; } } # Store a cleaned up version of the MakeMaker version, # since we need to behave differently in a variety of # ways based on the MM version. my $makemaker = eval $ExtUtils::MakeMaker::VERSION; # If we are passed a param, do a "newer than" comparison. # Otherwise, just return the MakeMaker version. sub makemaker { ( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0 } # Ripped from ExtUtils::MakeMaker 6.56, and slightly modified # as we only need to know here whether the attribute is an array # or a hash or something else (which may or may not be appendable). my %makemaker_argtype = ( C => 'ARRAY', CONFIG => 'ARRAY', # CONFIGURE => 'CODE', # ignore DIR => 'ARRAY', DL_FUNCS => 'HASH', DL_VARS => 'ARRAY', EXCLUDE_EXT => 'ARRAY', EXE_FILES => 'ARRAY', FUNCLIST => 'ARRAY', H => 'ARRAY', IMPORTS => 'HASH', INCLUDE_EXT => 'ARRAY', LIBS => 'ARRAY', # ignore '' MAN1PODS => 'HASH', MAN3PODS => 'HASH', META_ADD => 'HASH', META_MERGE => 'HASH', PL_FILES => 'HASH', PM => 'HASH', PMLIBDIRS => 'ARRAY', PMLIBPARENTDIRS => 'ARRAY', PREREQ_PM => 'HASH', CONFIGURE_REQUIRES => 'HASH', SKIP => 'ARRAY', TYPEMAPS => 'ARRAY', XS => 'HASH', # VERSION => ['version',''], # ignore # _KEEP_AFTER_FLUSH => '', clean => 'HASH', depend => 'HASH', dist => 'HASH', dynamic_lib=> 'HASH', linkext => 'HASH', macro => 'HASH', postamble => 'HASH', realclean => 'HASH', test => 'HASH', tool_autosplit => 'HASH', # special cases where you can use makemaker_append CCFLAGS => 'APPENDABLE', DEFINE => 'APPENDABLE', INC => 'APPENDABLE', LDDLFLAGS => 'APPENDABLE', LDFROM => 'APPENDABLE', ); sub makemaker_args { my ($self, %new_args) = @_; my $args = ( $self->{makemaker_args} ||= {} ); foreach my $key (keys %new_args) { if ($makemaker_argtype{$key}) { if ($makemaker_argtype{$key} eq 'ARRAY') { $args->{$key} = [] unless defined $args->{$key}; unless (ref $args->{$key} eq 'ARRAY') { $args->{$key} = [$args->{$key}] } push @{$args->{$key}}, ref $new_args{$key} eq 'ARRAY' ? @{$new_args{$key}} : $new_args{$key}; } elsif ($makemaker_argtype{$key} eq 'HASH') { $args->{$key} = {} unless defined $args->{$key}; foreach my $skey (keys %{ $new_args{$key} }) { $args->{$key}{$skey} = $new_args{$key}{$skey}; } } elsif ($makemaker_argtype{$key} eq 'APPENDABLE') { $self->makemaker_append($key => $new_args{$key}); } } else { if (defined $args->{$key}) { warn qq{MakeMaker attribute "$key" is overriden; use "makemaker_append" to append values\n}; } $args->{$key} = $new_args{$key}; } } return $args; } # For mm args that take multiple space-seperated args, # append an argument to the current list. sub makemaker_append { my $self = shift; my $name = shift; my $args = $self->makemaker_args; $args->{$name} = defined $args->{$name} ? join( ' ', $args->{$name}, @_ ) : join( ' ', @_ ); } sub build_subdirs { my $self = shift; my $subdirs = $self->makemaker_args->{DIR} ||= []; for my $subdir (@_) { push @$subdirs, $subdir; } } sub clean_files { my $self = shift; my $clean = $self->makemaker_args->{clean} ||= {}; %$clean = ( %$clean, FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), ); } sub realclean_files { my $self = shift; my $realclean = $self->makemaker_args->{realclean} ||= {}; %$realclean = ( %$realclean, FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), ); } sub libs { my $self = shift; my $libs = ref $_[0] ? shift : [ shift ]; $self->makemaker_args( LIBS => $libs ); } sub inc { my $self = shift; $self->makemaker_args( INC => shift ); } sub _wanted_t { } sub tests_recursive { my $self = shift; my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } my %tests = map { $_ => 1 } split / /, ($self->tests || ''); require File::Find; File::Find::find( sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 }, $dir ); $self->tests( join ' ', sort keys %tests ); } sub write { my $self = shift; die "&Makefile->write() takes no arguments\n" if @_; # Check the current Perl version my $perl_version = $self->perl_version; if ( $perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; } # Make sure we have a new enough MakeMaker require ExtUtils::MakeMaker; if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { # This previous attempted to inherit the version of # ExtUtils::MakeMaker in use by the module author, but this # was found to be untenable as some authors build releases # using future dev versions of EU:MM that nobody else has. # Instead, #toolchain suggests we use 6.59 which is the most # stable version on CPAN at time of writing and is, to quote # ribasushi, "not terminally fucked, > and tested enough". # TODO: We will now need to maintain this over time to push # the version up as new versions are released. $self->build_requires( 'ExtUtils::MakeMaker' => 6.59 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 ); } else { # Allow legacy-compatibility with 5.005 by depending on the # most recent EU:MM that supported 5.005. $self->build_requires( 'ExtUtils::MakeMaker' => 6.36 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 ); } # Generate the MakeMaker params my $args = $self->makemaker_args; $args->{DISTNAME} = $self->name; $args->{NAME} = $self->module_name || $self->name; $args->{NAME} =~ s/-/::/g; $args->{VERSION} = $self->version or die <<'EOT'; ERROR: Can't determine distribution version. Please specify it explicitly via 'version' in Makefile.PL, or set a valid $VERSION in a module, and provide its file path via 'version_from' (or 'all_from' if you prefer) in Makefile.PL. EOT if ( $self->tests ) { my @tests = split ' ', $self->tests; my %seen; $args->{test} = { TESTS => (join ' ', grep {!$seen{$_}++} @tests), }; } elsif ( $Module::Install::ExtraTests::use_extratests ) { # Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness. # So, just ignore our xt tests here. } elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) { $args->{test} = { TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ), }; } if ( $] >= 5.005 ) { $args->{ABSTRACT} = $self->abstract; $args->{AUTHOR} = join ', ', @{$self->author || []}; } if ( $self->makemaker(6.10) ) { $args->{NO_META} = 1; #$args->{NO_MYMETA} = 1; } if ( $self->makemaker(6.17) and $self->sign ) { $args->{SIGN} = 1; } unless ( $self->is_admin ) { delete $args->{SIGN}; } if ( $self->makemaker(6.31) and $self->license ) { $args->{LICENSE} = $self->license; } my $prereq = ($args->{PREREQ_PM} ||= {}); %$prereq = ( %$prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->requires) ); # Remove any reference to perl, PREREQ_PM doesn't support it delete $args->{PREREQ_PM}->{perl}; # Merge both kinds of requires into BUILD_REQUIRES my $build_prereq = ($args->{BUILD_REQUIRES} ||= {}); %$build_prereq = ( %$build_prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->configure_requires, $self->build_requires) ); # Remove any reference to perl, BUILD_REQUIRES doesn't support it delete $args->{BUILD_REQUIRES}->{perl}; # Delete bundled dists from prereq_pm, add it to Makefile DIR my $subdirs = ($args->{DIR} || []); if ($self->bundles) { my %processed; foreach my $bundle (@{ $self->bundles }) { my ($mod_name, $dist_dir) = @$bundle; delete $prereq->{$mod_name}; $dist_dir = File::Basename::basename($dist_dir); # dir for building this module if (not exists $processed{$dist_dir}) { if (-d $dist_dir) { # List as sub-directory to be processed by make push @$subdirs, $dist_dir; } # Else do nothing: the module is already present on the system $processed{$dist_dir} = undef; } } } unless ( $self->makemaker('6.55_03') ) { %$prereq = (%$prereq,%$build_prereq); delete $args->{BUILD_REQUIRES}; } if ( my $perl_version = $self->perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; if ( $self->makemaker(6.48) ) { $args->{MIN_PERL_VERSION} = $perl_version; } } if ($self->installdirs) { warn qq{old INSTALLDIRS (probably set by makemaker_args) is overriden by installdirs\n} if $args->{INSTALLDIRS}; $args->{INSTALLDIRS} = $self->installdirs; } my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_} ) } keys %$args; my $user_preop = delete $args{dist}->{PREOP}; if ( my $preop = $self->admin->preop($user_preop) ) { foreach my $key ( keys %$preop ) { $args{dist}->{$key} = $preop->{$key}; } } my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { my $self = shift; my $makefile_name = shift; my $top_class = ref($self->_top) || ''; my $top_version = $self->_top->VERSION || ''; my $preamble = $self->preamble ? "# Preamble by $top_class $top_version\n" . $self->preamble : ''; my $postamble = "# Postamble by $top_class $top_version\n" . ($self->postamble || ''); local *MAKEFILE; open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; eval { flock MAKEFILE, LOCK_EX }; my $makefile = do { local $/; }; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; # Module::Install will never be used to build the Core Perl # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; # XXX - This is currently unused; not sure if it breaks other MM-users # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; seek MAKEFILE, 0, SEEK_SET; truncate MAKEFILE, 0; print MAKEFILE "$preamble$makefile$postamble" or die $!; close MAKEFILE or die $!; 1; } sub preamble { my ($self, $text) = @_; $self->{preamble} = $text . $self->{preamble} if defined $text; $self->{preamble}; } sub postamble { my ($self, $text) = @_; $self->{postamble} ||= $self->admin->postamble; $self->{postamble} .= $text if defined $text; $self->{postamble} } 1; __END__ #line 544 AnyEvent-Redis-0.24/inc/Module/Install/AuthorTests.pm0000644000175000001440000000221512062127517021153 0ustar dglusers#line 1 package Module::Install::AuthorTests; use 5.005; use strict; use Module::Install::Base; use Carp (); #line 16 use vars qw{$VERSION $ISCORE @ISA}; BEGIN { $VERSION = '0.002'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } #line 42 sub author_tests { my ($self, @dirs) = @_; _add_author_tests($self, \@dirs, 0); } #line 56 sub recursive_author_tests { my ($self, @dirs) = @_; _add_author_tests($self, \@dirs, 1); } sub _wanted { my $href = shift; sub { /\.t$/ and -f $_ and $href->{$File::Find::dir} = 1 } } sub _add_author_tests { my ($self, $dirs, $recurse) = @_; return unless $Module::Install::AUTHOR; my @tests = $self->tests ? (split / /, $self->tests) : 't/*.t'; # XXX: pick a default, later -- rjbs, 2008-02-24 my @dirs = @$dirs ? @$dirs : Carp::confess "no dirs given to author_tests"; @dirs = grep { -d } @dirs; if ($recurse) { require File::Find; my %test_dir; File::Find::find(_wanted(\%test_dir), @dirs); $self->tests( join ' ', @tests, map { "$_/*.t" } sort keys %test_dir ); } else { $self->tests( join ' ', @tests, map { "$_/*.t" } sort @dirs ); } } #line 107 1; AnyEvent-Redis-0.24/inc/Module/Install/Metadata.pm0000644000175000001440000004327712062127517020423 0ustar dglusers#line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } my @boolean_keys = qw{ sign }; my @scalar_keys = qw{ name module_name abstract version distribution_type tests installdirs }; my @tuple_keys = qw{ configure_requires build_requires requires recommends bundles resources }; my @resource_keys = qw{ homepage bugtracker repository }; my @array_keys = qw{ keywords author }; *authors = \&author; sub Meta { shift } sub Meta_BooleanKeys { @boolean_keys } sub Meta_ScalarKeys { @scalar_keys } sub Meta_TupleKeys { @tuple_keys } sub Meta_ResourceKeys { @resource_keys } sub Meta_ArrayKeys { @array_keys } foreach my $key ( @boolean_keys ) { *$key = sub { my $self = shift; if ( defined wantarray and not @_ ) { return $self->{values}->{$key}; } $self->{values}->{$key} = ( @_ ? $_[0] : 1 ); return $self; }; } foreach my $key ( @scalar_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} = shift; return $self; }; } foreach my $key ( @array_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} ||= []; push @{$self->{values}->{$key}}, @_; return $self; }; } foreach my $key ( @resource_keys ) { *$key = sub { my $self = shift; unless ( @_ ) { return () unless $self->{values}->{resources}; return map { $_->[1] } grep { $_->[0] eq $key } @{ $self->{values}->{resources} }; } return $self->{values}->{resources}->{$key} unless @_; my $uri = shift or die( "Did not provide a value to $key()" ); $self->resources( $key => $uri ); return 1; }; } foreach my $key ( grep { $_ ne "resources" } @tuple_keys) { *$key = sub { my $self = shift; return $self->{values}->{$key} unless @_; my @added; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @added, [ $module, $version ]; } push @{ $self->{values}->{$key} }, @added; return map {@$_} @added; }; } # Resource handling my %lc_resource = map { $_ => 1 } qw{ homepage license bugtracker repository }; sub resources { my $self = shift; while ( @_ ) { my $name = shift or last; my $value = shift or next; if ( $name eq lc $name and ! $lc_resource{$name} ) { die("Unsupported reserved lowercase resource '$name'"); } $self->{values}->{resources} ||= []; push @{ $self->{values}->{resources} }, [ $name, $value ]; } $self->{values}->{resources}; } # Aliases for build_requires that will have alternative # meanings in some future version of META.yml. sub test_requires { shift->build_requires(@_) } sub install_requires { shift->build_requires(@_) } # Aliases for installdirs options sub install_as_core { $_[0]->installdirs('perl') } sub install_as_cpan { $_[0]->installdirs('site') } sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub dynamic_config { my $self = shift; my $value = @_ ? shift : 1; if ( $self->{values}->{dynamic_config} ) { # Once dynamic we never change to static, for safety return 0; } $self->{values}->{dynamic_config} = $value ? 1 : 0; return 1; } # Convenience command sub static_config { shift->dynamic_config(0); } sub perl_version { my $self = shift; return $self->{values}->{perl_version} unless @_; my $version = shift or die( "Did not provide a value to perl_version()" ); # Normalize the version $version = $self->_perl_version($version); # We don't support the really old versions unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } $self->{values}->{perl_version} = $version; } sub all_from { my ( $self, $file ) = @_; unless ( defined($file) ) { my $name = $self->name or die( "all_from called with no args without setting name() first" ); $file = join('/', 'lib', split(/-/, $name)) . '.pm'; $file =~ s{.*/}{} unless -e $file; unless ( -e $file ) { die("all_from cannot find $file from $name"); } } unless ( -f $file ) { die("The path '$file' does not exist, or is not a file"); } $self->{values}{all_from} = $file; # Some methods pull from POD instead of code. # If there is a matching .pod, use that instead my $pod = $file; $pod =~ s/\.pm$/.pod/i; $pod = $file unless -e $pod; # Pull the different values $self->name_from($file) unless $self->name; $self->version_from($file) unless $self->version; $self->perl_version_from($file) unless $self->perl_version; $self->author_from($pod) unless @{$self->author || []}; $self->license_from($pod) unless $self->license; $self->abstract_from($pod) unless $self->abstract; return 1; } sub provides { my $self = shift; my $provides = ( $self->{values}->{provides} ||= {} ); %$provides = (%$provides, @_) if @_; return $provides; } sub auto_provides { my $self = shift; return $self unless $self->is_admin; unless (-e 'MANIFEST') { warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; return $self; } # Avoid spurious warnings as we are not checking manifest here. local $SIG{__WARN__} = sub {1}; require ExtUtils::Manifest; local *ExtUtils::Manifest::manicheck = sub { return }; require Module::Build; my $build = Module::Build->new( dist_name => $self->name, dist_version => $self->version, license => $self->license, ); $self->provides( %{ $build->find_dist_packages || {} } ); } sub feature { my $self = shift; my $name = shift; my $features = ( $self->{values}->{features} ||= [] ); my $mods; if ( @_ == 1 and ref( $_[0] ) ) { # The user used ->feature like ->features by passing in the second # argument as a reference. Accomodate for that. $mods = $_[0]; } else { $mods = \@_; } my $count = 0; push @$features, ( $name => [ map { ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ } @$mods ] ); return @$features; } sub features { my $self = shift; while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { $self->feature( $name, @$mods ); } return $self->{values}->{features} ? @{ $self->{values}->{features} } : (); } sub no_index { my $self = shift; my $type = shift; push @{ $self->{values}->{no_index}->{$type} }, @_ if $type; return $self->{values}->{no_index}; } sub read { my $self = shift; $self->include_deps( 'YAML::Tiny', 0 ); require YAML::Tiny; my $data = YAML::Tiny::LoadFile('META.yml'); # Call methods explicitly in case user has already set some values. while ( my ( $key, $value ) = each %$data ) { next unless $self->can($key); if ( ref $value eq 'HASH' ) { while ( my ( $module, $version ) = each %$value ) { $self->can($key)->($self, $module => $version ); } } else { $self->can($key)->($self, $value); } } return $self; } sub write { my $self = shift; return $self unless $self->is_admin; $self->admin->write_meta; return $self; } sub version_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->version( ExtUtils::MM_Unix->parse_version($file) ); # for version integrity check $self->makemaker_args( VERSION_FROM => $file ); } sub abstract_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->abstract( bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($file) ); } # Add both distribution and module name sub name_from { my ($self, $file) = @_; if ( Module::Install::_read($file) =~ m/ ^ \s* package \s* ([\w:]+) \s* ; /ixms ) { my ($name, $module_name) = ($1, $1); $name =~ s{::}{-}g; $self->name($name); unless ( $self->module_name ) { $self->module_name($module_name); } } else { die("Cannot determine name from $file\n"); } } sub _extract_perl_version { if ( $_[0] =~ m/ ^\s* (?:use|require) \s* v? ([\d_\.]+) \s* ; /ixms ) { my $perl_version = $1; $perl_version =~ s{_}{}g; return $perl_version; } else { return; } } sub perl_version_from { my $self = shift; my $perl_version=_extract_perl_version(Module::Install::_read($_[0])); if ($perl_version) { $self->perl_version($perl_version); } else { warn "Cannot determine perl version info from $_[0]\n"; return; } } sub author_from { my $self = shift; my $content = Module::Install::_read($_[0]); if ($content =~ m/ =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /ixms) { my $author = $1 || $2; # XXX: ugly but should work anyway... if (eval "require Pod::Escapes; 1") { # Pod::Escapes has a mapping table. # It's in core of perl >= 5.9.3, and should be installed # as one of the Pod::Simple's prereqs, which is a prereq # of Pod::Text 3.x (see also below). $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $Pod::Escapes::Name2character_number{$1} ? chr($Pod::Escapes::Name2character_number{$1}) : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) { # Pod::Text < 3.0 has yet another mapping table, # though the table name of 2.x and 1.x are different. # (1.x is in core of Perl < 5.6, 2.x is in core of # Perl < 5.9.3) my $mapping = ($Pod::Text::VERSION < 2) ? \%Pod::Text::HTML_Escapes : \%Pod::Text::ESCAPES; $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $mapping->{$1} ? $mapping->{$1} : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } else { $author =~ s{E}{<}g; $author =~ s{E}{>}g; } $self->author($author); } else { warn "Cannot determine author info from $_[0]\n"; } } #Stolen from M::B my %license_urls = ( perl => 'http://dev.perl.org/licenses/', apache => 'http://apache.org/licenses/LICENSE-2.0', apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1', artistic => 'http://opensource.org/licenses/artistic-license.php', artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', lgpl => 'http://opensource.org/licenses/lgpl-license.php', lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', bsd => 'http://opensource.org/licenses/bsd-license.php', gpl => 'http://opensource.org/licenses/gpl-license.php', gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', mit => 'http://opensource.org/licenses/mit-license.php', mozilla => 'http://opensource.org/licenses/mozilla1.1.php', open_source => undef, unrestricted => undef, restrictive => undef, unknown => undef, ); sub license { my $self = shift; return $self->{values}->{license} unless @_; my $license = shift or die( 'Did not provide a value to license()' ); $license = __extract_license($license) || lc $license; $self->{values}->{license} = $license; # Automatically fill in license URLs if ( $license_urls{$license} ) { $self->resources( license => $license_urls{$license} ); } return 1; } sub _extract_license { my $pod = shift; my $matched; return __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /xms ) || __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /xms ); } sub __extract_license { my $license_text = shift or return; my @phrases = ( '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1, '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1, 'Artistic and GPL' => 'perl', 1, 'GNU general public license' => 'gpl', 1, 'GNU public license' => 'gpl', 1, 'GNU lesser general public license' => 'lgpl', 1, 'GNU lesser public license' => 'lgpl', 1, 'GNU library general public license' => 'lgpl', 1, 'GNU library public license' => 'lgpl', 1, 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, 'LGPL' => 'lgpl', 1, 'BSD' => 'bsd', 1, 'Artistic' => 'artistic', 1, 'MIT' => 'mit', 1, 'Mozilla Public License' => 'mozilla', 1, 'Q Public License' => 'open_source', 1, 'OpenSSL License' => 'unrestricted', 1, 'SSLeay License' => 'unrestricted', 1, 'zlib License' => 'open_source', 1, 'proprietary' => 'proprietary', 0, ); while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s#\s+#\\s+#gs; if ( $license_text =~ /\b$pattern\b/i ) { return $license; } } return ''; } sub license_from { my $self = shift; if (my $license=_extract_license(Module::Install::_read($_[0]))) { $self->license($license); } else { warn "Cannot determine license info from $_[0]\n"; return 'unknown'; } } sub _extract_bugtracker { my @links = $_[0] =~ m#L<( https?\Q://rt.cpan.org/\E[^>]+| https?\Q://github.com/\E[\w_]+/[\w_]+/issues| https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); @links=keys %links; return @links; } sub bugtracker_from { my $self = shift; my $content = Module::Install::_read($_[0]); my @links = _extract_bugtracker($content); unless ( @links ) { warn "Cannot determine bugtracker info from $_[0]\n"; return 0; } if ( @links > 1 ) { warn "Found more than one bugtracker link in $_[0]\n"; return 0; } # Set the bugtracker bugtracker( $links[0] ); return 1; } sub requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->requires( $module => $version ); } } sub test_requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->test_requires( $module => $version ); } } # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to # numbers (eg, 5.006001 or 5.008009). # Also, convert double-part versions (eg, 5.8) sub _perl_version { my $v = $_[-1]; $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e; $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e; $v =~ s/(\.\d\d\d)000$/$1/; $v =~ s/_.+$//; if ( ref($v) ) { # Numify $v = $v + 0; } return $v; } sub add_metadata { my $self = shift; my %hash = @_; for my $key (keys %hash) { warn "add_metadata: $key is not prefixed with 'x_'.\n" . "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/; $self->{values}->{$key} = $hash{$key}; } } ###################################################################### # MYMETA Support sub WriteMyMeta { die "WriteMyMeta has been deprecated"; } sub write_mymeta_yaml { my $self = shift; # We need YAML::Tiny to write the MYMETA.yml file unless ( eval { require YAML::Tiny; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.yml\n"; YAML::Tiny::DumpFile('MYMETA.yml', $meta); } sub write_mymeta_json { my $self = shift; # We need JSON to write the MYMETA.json file unless ( eval { require JSON; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.json\n"; Module::Install::_write( 'MYMETA.json', JSON->new->pretty(1)->canonical->encode($meta), ); } sub _write_mymeta_data { my $self = shift; # If there's no existing META.yml there is nothing we can do return undef unless -f 'META.yml'; # We need Parse::CPAN::Meta to load the file unless ( eval { require Parse::CPAN::Meta; 1; } ) { return undef; } # Merge the perl version into the dependencies my $val = $self->Meta->{values}; my $perl = delete $val->{perl_version}; if ( $perl ) { $val->{requires} ||= []; my $requires = $val->{requires}; # Canonize to three-dot version after Perl 5.6 if ( $perl >= 5.006 ) { $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e } unshift @$requires, [ perl => $perl ]; } # Load the advisory META.yml file my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); my $meta = $yaml[0]; # Overwrite the non-configure dependency hashs delete $meta->{requires}; delete $meta->{build_requires}; delete $meta->{recommends}; if ( exists $val->{requires} ) { $meta->{requires} = { map { @$_ } @{ $val->{requires} } }; } if ( exists $val->{build_requires} ) { $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } }; } return $meta; } 1; AnyEvent-Redis-0.24/inc/Module/Install/Repository.pm0000644000175000001440000000425612062127517021054 0ustar dglusers#line 1 package Module::Install::Repository; use strict; use 5.005; use vars qw($VERSION); $VERSION = '0.06'; use base qw(Module::Install::Base); sub _execute { my ($command) = @_; `$command`; } sub auto_set_repository { my $self = shift; return unless $Module::Install::AUTHOR; my $repo = _find_repo(\&_execute); if ($repo) { $self->repository($repo); } else { warn "Cannot determine repository URL\n"; } } sub _find_repo { my ($execute) = @_; if (-e ".git") { # TODO support remote besides 'origin'? if ($execute->('git remote show -n origin') =~ /URL: (.*)$/m) { # XXX Make it public clone URL, but this only works with github my $git_url = $1; $git_url =~ s![\w\-]+\@([^:]+):!git://$1/!; return $git_url; } elsif ($execute->('git svn info') =~ /URL: (.*)$/m) { return $1; } } elsif (-e ".svn") { if (`svn info` =~ /URL: (.*)$/m) { return $1; } } elsif (-e "_darcs") { # defaultrepo is better, but that is more likely to be ssh, not http if (my $query_repo = `darcs query repo`) { if ($query_repo =~ m!Default Remote: (http://.+)!) { return $1; } } open my $handle, '<', '_darcs/prefs/repos' or return; while (<$handle>) { chomp; return $_ if m!^http://!; } } elsif (-e ".hg") { if ($execute->('hg paths') =~ /default = (.*)$/m) { my $mercurial_url = $1; $mercurial_url =~ s!^ssh://hg\@(bitbucket\.org/)!https://$1!; return $mercurial_url; } } elsif (-e "$ENV{HOME}/.svk") { # Is there an explicit way to check if it's an svk checkout? my $svk_info = `svk info` or return; SVK_INFO: { if ($svk_info =~ /Mirrored From: (.*), Rev\./) { return $1; } if ($svk_info =~ m!Merged From: (/mirror/.*), Rev\.!) { $svk_info = `svk info /$1` or return; redo SVK_INFO; } } return; } } 1; __END__ =encoding utf-8 #line 128 AnyEvent-Redis-0.24/inc/Module/Install/WriteAll.pm0000644000175000001440000000237612062127517020421 0ustar dglusers#line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } sub WriteAll { my $self = shift; my %args = ( meta => 1, sign => 0, inline => 0, check_nmake => 1, @_, ); $self->sign(1) if $args{sign}; $self->admin->WriteAll(%args) if $self->is_admin; $self->check_nmake if $args{check_nmake}; unless ( $self->makemaker_args->{PL_FILES} ) { # XXX: This still may be a bit over-defensive... unless ($self->makemaker(6.25)) { $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL'; } } # Until ExtUtils::MakeMaker support MYMETA.yml, make sure # we clean it up properly ourself. $self->realclean_files('MYMETA.yml'); if ( $args{inline} ) { $self->Inline->write; } else { $self->Makefile->write; } # The Makefile write process adds a couple of dependencies, # so write the META.yml files after the Makefile. if ( $args{meta} ) { $self->Meta->write; } # Experimental support for MYMETA if ( $ENV{X_MYMETA} ) { if ( $ENV{X_MYMETA} eq 'JSON' ) { $self->Meta->write_mymeta_json; } else { $self->Meta->write_mymeta_yaml; } } return 1; } 1; AnyEvent-Redis-0.24/inc/Module/Install/Win32.pm0000644000175000001440000000340312062127517017570 0ustar dglusers#line 1 package Module::Install::Win32; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # determine if the user needs nmake, and download it if needed sub check_nmake { my $self = shift; $self->load('can_run'); $self->load('get_file'); require Config; return unless ( $^O eq 'MSWin32' and $Config::Config{make} and $Config::Config{make} =~ /^nmake\b/i and ! $self->can_run('nmake') ); print "The required 'nmake' executable not found, fetching it...\n"; require File::Basename; my $rv = $self->get_file( url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', local_dir => File::Basename::dirname($^X), size => 51928, run => 'Nmake15.exe /o > nul', check_for => 'Nmake.exe', remove => 1, ); die <<'END_MESSAGE' unless $rv; ------------------------------------------------------------------------------- Since you are using Microsoft Windows, you will need the 'nmake' utility before installation. It's available at: http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe or ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe Please download the file manually, save it to a directory in %PATH% (e.g. C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to that directory, and run "Nmake15.exe" from there; that will create the 'nmake.exe' file needed by this module. You may then resume the installation process described in README. ------------------------------------------------------------------------------- END_MESSAGE } 1; AnyEvent-Redis-0.24/inc/Module/Install/Fetch.pm0000644000175000001440000000462712062127517017730 0ustar dglusers#line 1 package Module::Install::Fetch; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub get_file { my ($self, %args) = @_; my ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { $args{url} = $args{ftp_url} or (warn("LWP support unavailable!\n"), return); ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; } $|++; print "Fetching '$file' from $host... "; unless (eval { require Socket; Socket::inet_aton($host) }) { warn "'$host' resolve failed!\n"; return; } return unless $scheme eq 'ftp' or $scheme eq 'http'; require Cwd; my $dir = Cwd::getcwd(); chdir $args{local_dir} or return if exists $args{local_dir}; if (eval { require LWP::Simple; 1 }) { LWP::Simple::mirror($args{url}, $file); } elsif (eval { require Net::FTP; 1 }) { eval { # use Net::FTP to get past firewall my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); $ftp->login("anonymous", 'anonymous@example.com'); $ftp->cwd($path); $ftp->binary; $ftp->get($file) or (warn("$!\n"), return); $ftp->quit; } } elsif (my $ftp = $self->can_run('ftp')) { eval { # no Net::FTP, fallback to ftp.exe require FileHandle; my $fh = FileHandle->new; local $SIG{CHLD} = 'IGNORE'; unless ($fh->open("|$ftp -n")) { warn "Couldn't open ftp: $!\n"; chdir $dir; return; } my @dialog = split(/\n/, <<"END_FTP"); open $host user anonymous anonymous\@example.com cd $path binary get $file $file quit END_FTP foreach (@dialog) { $fh->print("$_\n") } $fh->close; } } else { warn "No working 'ftp' program available!\n"; chdir $dir; return; } unless (-f $file) { warn "Fetching failed: $@\n"; chdir $dir; return; } return if exists $args{size} and -s $file != $args{size}; system($args{run}) if exists $args{run}; unlink($file) if $args{remove}; print(((!exists $args{check_for} or -e $args{check_for}) ? "done!" : "failed! ($!)"), "\n"); chdir $dir; return !$?; } 1; AnyEvent-Redis-0.24/inc/Module/Install/ReadmeFromPod.pm0000644000175000001440000000631112062127517021353 0ustar dglusers#line 1 package Module::Install::ReadmeFromPod; use 5.006; use strict; use warnings; use base qw(Module::Install::Base); use vars qw($VERSION); $VERSION = '0.18'; sub readme_from { my $self = shift; return unless $self->is_admin; # Input file my $in_file = shift || $self->_all_from or die "Can't determine file to make readme_from"; # Get optional arguments my ($clean, $format, $out_file, $options); my $args = shift; if ( ref $args ) { # Arguments are in a hashref if ( ref($args) ne 'HASH' ) { die "Expected a hashref but got a ".ref($args)."\n"; } else { $clean = $args->{'clean'}; $format = $args->{'format'}; $out_file = $args->{'output_file'}; $options = $args->{'options'}; } } else { # Arguments are in a list $clean = $args; $format = shift; $out_file = shift; $options = \@_; } # Default values; $clean ||= 0; $format ||= 'txt'; # Generate README print "readme_from $in_file to $format\n"; if ($format =~ m/te?xt/) { $out_file = $self->_readme_txt($in_file, $out_file, $options); } elsif ($format =~ m/html?/) { $out_file = $self->_readme_htm($in_file, $out_file, $options); } elsif ($format eq 'man') { $out_file = $self->_readme_man($in_file, $out_file, $options); } elsif ($format eq 'pdf') { $out_file = $self->_readme_pdf($in_file, $out_file, $options); } if ($clean) { $self->clean_files($out_file); } return 1; } sub _readme_txt { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README'; require Pod::Text; my $parser = Pod::Text->new( @$options ); open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; $parser->output_fh( *$out_fh ); $parser->parse_file( $in_file ); close $out_fh; return $out_file; } sub _readme_htm { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.htm'; require Pod::Html; Pod::Html::pod2html( "--infile=$in_file", "--outfile=$out_file", @$options, ); # Remove temporary files if needed for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') { if (-e $file) { unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n"; } } return $out_file; } sub _readme_man { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.1'; require Pod::Man; my $parser = Pod::Man->new( @$options ); $parser->parse_from_file($in_file, $out_file); return $out_file; } sub _readme_pdf { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.pdf'; eval { require App::pod2pdf; } or die "Could not generate $out_file because pod2pdf could not be found\n"; my $parser = App::pod2pdf->new( @$options ); $parser->parse_from_file($in_file); open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; select $out_fh; $parser->output; select STDOUT; close $out_fh; return $out_file; } sub _all_from { my $self = shift; return unless $self->admin->{extensions}; my ($metadata) = grep { ref($_) eq 'Module::Install::Metadata'; } @{$self->admin->{extensions}}; return unless $metadata; return $metadata->{values}{all_from} || ''; } 'Readme!'; __END__ #line 254 AnyEvent-Redis-0.24/inc/Module/Install/Base.pm0000644000175000001440000000214712062127517017544 0ustar dglusers#line 1 package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { $VERSION = '1.06'; } # Suspend handler for "redefined" warnings BEGIN { my $w = $SIG{__WARN__}; $SIG{__WARN__} = sub { $w }; } #line 42 sub new { my $class = shift; unless ( defined &{"${class}::call"} ) { *{"${class}::call"} = sub { shift->_top->call(@_) }; } unless ( defined &{"${class}::load"} ) { *{"${class}::load"} = sub { shift->_top->load(@_) }; } bless { @_ }, $class; } #line 61 sub AUTOLOAD { local $@; my $func = eval { shift->_top->autoload } or return; goto &$func; } #line 75 sub _top { $_[0]->{_top}; } #line 90 sub admin { $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new; } #line 106 sub is_admin { ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin'); } sub DESTROY {} package Module::Install::Base::FakeAdmin; use vars qw{$VERSION}; BEGIN { $VERSION = $Module::Install::Base::VERSION; } my $fake; sub new { $fake ||= bless(\@_, $_[0]); } sub AUTOLOAD {} sub DESTROY {} # Restore warning handler BEGIN { $SIG{__WARN__} = $SIG{__WARN__}->(); } 1; #line 159 AnyEvent-Redis-0.24/inc/Module/Install/Can.pm0000644000175000001440000000615712062127517017400 0ustar dglusers#line 1 package Module::Install::Can; use strict; use Config (); use ExtUtils::MakeMaker (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # check if we can load some module ### Upgrade this to not have to load the module if possible sub can_use { my ($self, $mod, $ver) = @_; $mod =~ s{::|\\}{/}g; $mod .= '.pm' unless $mod =~ /\.pm$/i; my $pkg = $mod; $pkg =~ s{/}{::}g; $pkg =~ s{\.pm$}{}i; local $@; eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } # Check if we can run some command sub can_run { my ($self, $cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; require File::Spec; my $abs = File::Spec->catfile($dir, $cmd); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # Can our C compiler environment build XS files sub can_xs { my $self = shift; # Ensure we have the CBuilder module $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 ); # Do we have the configure_requires checker? local $@; eval "require ExtUtils::CBuilder;"; if ( $@ ) { # They don't obey configure_requires, so it is # someone old and delicate. Try to avoid hurting # them by falling back to an older simpler test. return $self->can_cc(); } # Do we have a working C compiler my $builder = ExtUtils::CBuilder->new( quiet => 1, ); unless ( $builder->have_compiler ) { # No working C compiler return 0; } # Write a C file representative of what XS becomes require File::Temp; my ( $FH, $tmpfile ) = File::Temp::tempfile( "compilexs-XXXXX", SUFFIX => '.c', ); binmode $FH; print $FH <<'END_C'; #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int main(int argc, char **argv) { return 0; } int boot_sanexs() { return 1; } END_C close $FH; # Can the C compiler access the same headers XS does my @libs = (); my $object = undef; eval { local $^W = 0; $object = $builder->compile( source => $tmpfile, ); @libs = $builder->link( objects => $object, module_name => 'sanexs', ); }; my $result = $@ ? 0 : 1; # Clean up all the build files foreach ( $tmpfile, $object, @libs ) { next unless defined $_; 1 while unlink; } return $result; } # Can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return $self->can_run("@chunks") || (pop(@chunks), next); } return; } # Fix Cygwin bug on maybe_command(); if ( $^O eq 'cygwin' ) { require ExtUtils::MM_Cygwin; require ExtUtils::MM_Win32; if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { *ExtUtils::MM_Cygwin::maybe_command = sub { my ($self, $file) = @_; if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { ExtUtils::MM_Win32->maybe_command($file); } else { ExtUtils::MM_Unix->maybe_command($file); } } } } 1; __END__ #line 236 AnyEvent-Redis-0.24/Changes0000644000175000001440000000465212062127407014224 0ustar dglusersRevision history for Perl extension AnyEvent::Redis 0.24 Wed 12 Dec 16:18:42 GMT 2012 - Many error handling improvements (chip) - Reconnect logic (leedo) - Fix for tests with redis-server 2.6 (typester) - Fix leak of connections (dgl) 0.23 Wed 12 Jan 2011 23:34:58 GMT - Fix to always allow condvar as final param (chip) 0.23_01 Wed Dec 15 20:17:42 PST 2010 - Added character encoding support (mfischer, dgl) - New read handler, about 10% faster (mfischer) - Moved read handler to AnyEvent::Redis::Protocol (mfischer) - Updated documentation (mfischer) 0.22 Sun Oct 31 20:38:52 PDT 2010 - Fixed memory leaks with MULTI commands (dgl) 0.21 Fri Oct 29 15:18:52 PDT 2010 - Fixed async buffering issue with LRANGE command (leedo, dgl) - Fixed circular reference memory leaks (jzawodny) 0.20 Sun Sep 12 12:46:36 PDT 2010 - cleanup on connection failure (leedo) 0.19_01 Wed Aug 25 12:46:59 PDT 2010 - Added PubSub support (dgl) - Documentations improved (dgl) - Fixed KEYS for 1.2 server (dgl) - Bumped Test::TCP dep (dgl) 0.12 Sun Aug 8 23:34:59 PDT 2010 - Added HSETNX (clkao) - Reset the state when EOF or on error (clkao) 0.11 Fri Aug 6 23:09:41 PDT 2010 - Refactored the decoder so nested MULTI/EXEC responses work (clkao) 0.10 Fri Jul 2 17:02:16 PDT 2010 - Support command operations on hashes for Redis 2.0 (franck) - Fixed MGET on non-existent keys (franck) 0.09 Thu Apr 15 10:46:46 PDT 2010 - Fixed the test (hanekomu) 0.08 Tue Mar 9 11:44:33 JST 2010 - Immediately send [] if the length is 0 for multi-bulk replies (leedo) 0.07 Tue Feb 23 15:40:02 PST 2010 - Bug fix to handle nonexistent keys in multi-bulk replies (jbarratt) 0.06 Mon Feb 15 19:20:50 PST 2010 - Add more bulk commands: getset, smove, zadd, zrem, zscore, zincrby, append (Leon Brocard) 0.05 Fri Feb 12 10:33:44 PST 2010 - Fixed a typo in the on_error callback (jzawodn) 0.04 Tue Nov 10 22:55:59 PST 2009 - Fixed deps 0.03 Tue Nov 10 20:33:38 PST 2009 - Changed the object construction API to always use new() - Implemented on_error for callback based error handling 0.02 Tue Nov 10 17:49:39 PST 2009 - Fixed all_cv interface - Fixed redis-server check in tests 0.01 Sun Nov 8 00:51:03 2009 - original version AnyEvent-Redis-0.24/xt/0000755000175000001440000000000012062127520013351 5ustar dglusersAnyEvent-Redis-0.24/xt/synopsis.t0000644000175000001440000000016011735272724015437 0ustar dglusersuse Test::More; eval "use Test::Synopsis"; plan skip_all => "Test::Synopsis required" if $@; all_synopsis_ok(); AnyEvent-Redis-0.24/xt/podspell.t0000644000175000001440000000063212036524033015362 0ustar dglusersuse Test::More; eval q{ use Test::Spelling; add_stopwords(qw( multi unsubscribe unsubscribing versa )); }; plan skip_all => "Test::Spelling is not installed." if $@; add_stopwords(); set_spell_cmd("aspell -l en list"); all_pod_files_spelling_ok('lib'); __DATA__ Tatsuhiko Miyagawa AnyEvent Redis Aylward Barratt Brocard Chia Kao Leadbeater Zawodny cuny franck hget hostname hset liang lpop lpush AnyEvent-Redis-0.24/xt/pod.t0000644000175000001440000000020111735272724014326 0ustar dglusersuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); AnyEvent-Redis-0.24/xt/perlcritic.t0000644000175000001440000000022311735272724015710 0ustar dglusersuse strict; use Test::More; eval q{ use Test::Perl::Critic }; plan skip_all => "Test::Perl::Critic is not installed." if $@; all_critic_ok("lib"); AnyEvent-Redis-0.24/MANIFEST0000644000175000001440000000122112062127074014047 0ustar dglusers.gitignore Changes inc/Module/Install.pm inc/Module/Install/AuthorTests.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/ReadmeFromPod.pm inc/Module/Install/Repository.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/AnyEvent/Redis.pm lib/AnyEvent/Redis/Error.pm lib/AnyEvent/Redis/Protocol.pm Makefile.PL MANIFEST This list of files META.yml README t/00_compile.t t/client.t t/leak.t t/lrange.t t/multi.t t/pubsub.t t/reconnect.t t/redis.conf.base t/Redis.pm t/utf8.t xt/perlcritic.t xt/pod.t xt/podspell.t xt/synopsis.t AnyEvent-Redis-0.24/lib/0000755000175000001440000000000012062127520013464 5ustar dglusersAnyEvent-Redis-0.24/lib/AnyEvent/0000755000175000001440000000000012062127520015215 5ustar dglusersAnyEvent-Redis-0.24/lib/AnyEvent/Redis/0000755000175000001440000000000012062127520016263 5ustar dglusersAnyEvent-Redis-0.24/lib/AnyEvent/Redis/Protocol.pm0000644000175000001440000001426212036524033020430 0ustar dgluserspackage AnyEvent::Redis::Protocol; use strict; use warnings; =head1 NAME AnyEvent::Redis::Protocol - Redis response parser (read handler) for AnyEvent =head1 DESCRIPTION This package should not be directly used. It provides an AnyEvent read handler capable of parsing Redis responses. =head1 SEE ALSO L, Redis Protocol Specification L =cut sub anyevent_read_type { my ($handle, $cb) = @_; return sub { $handle->push_read(line => sub { my $line = $_[1]; my $type = substr($line, 0, 1); my $value = substr($line, 1); if ($type eq '*') { # Multi-bulk reply my $remaining = $value; if ($remaining == 0) { $cb->([]); } elsif ($remaining == -1) { $cb->(undef); } else { my $results = []; $handle->unshift_read(sub { my $need_more_data = 0; do { if ($handle->{rbuf} =~ /^(\$(-?\d+)\015\012)/) { my ($match, $vallen) = ($1, $2); if ($vallen == -1) { # Delete the bulk header. substr($handle->{rbuf}, 0, length($match), ''); push @$results, undef; unless (--$remaining) { $cb->($results); return 1; } } elsif (length $handle->{rbuf} >= (length($match) + $vallen + 2)) { # OK, we have enough in our buffer. # Delete the bulk header. substr($handle->{rbuf}, 0, length($match), ''); my $value = substr($handle->{rbuf}, 0, $vallen, ''); $value = $handle->{encoding}->decode($value) if $handle->{encoding} && $vallen; push @$results, $value; # Delete trailing data characters. substr($handle->{rbuf}, 0, 2, ''); unless (--$remaining) { $cb->($results); return 1; } } else { $need_more_data = 1; } } elsif ($handle->{rbuf} =~ s/^([\+\-:])([^\015\012]*)\015\012//) { my ($type, $value) = ($1, $2); if ($type eq '+' || $type eq ':') { push @$results, $value; } elsif ($type eq '-') { # Embedded error; this seems possible only in EXEC answer, # so include error in results; don't abort parsing push @$results, bless \$value, 'AnyEvent::Redis::Error'; } unless (--$remaining) { $cb->($results); return 1; } } elsif (substr($handle->{rbuf}, 0, 1) eq '*') { # Oh, how fun! A nested bulk reply. my $reader; $reader = sub { $handle->unshift_read("AnyEvent::Redis::Protocol" => sub { push @$results, $_[0]; if (--$remaining) { $reader->(); } else { undef $reader; $cb->($results); } }); }; $reader->(); return 1; } else { # Nothing matched - read more... $need_more_data = 1; } } until $need_more_data; return; # get more data }); } } elsif ($type eq '+' || $type eq ':') { # Single line/integer reply $cb->($value); } elsif ($type eq '-') { # Single-line error reply $cb->($value, 1); } elsif ($type eq '$') { # Bulk reply my $length = $value; if ($length == -1) { $cb->(undef); } else { # We need to read 2 bytes more than the length (stupid # CRLF framing). Then we need to discard them. $handle->unshift_read(chunk => $length + 2, sub { my $data = $_[1]; my $value = substr($data, 0, $length); $value = $handle->{encoding}->decode($value) if $handle->{encoding} && $length; $cb->($value); }); } } return 1; }); return 1; }; } =head1 AUTHOR Michael S. Fischer =head1 COPYRIGHT AND LICENSE Copyright (C) 2010 Michael S. Fischer. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 1; __END__ # vim:syn=perl:ts=4:sw=4:et:ai AnyEvent-Redis-0.24/lib/AnyEvent/Redis/Error.pm0000644000175000001440000000013712036524033017714 0ustar dgluserspackage AnyEvent::Redis::Error; use strict; use warnings; sub message { ${ $_[0] } } 1; AnyEvent-Redis-0.24/lib/AnyEvent/Redis.pm0000644000175000001440000003561312062126632016634 0ustar dgluserspackage AnyEvent::Redis; use strict; use 5.008_001; our $VERSION = '0.24'; use constant DEBUG => $ENV{ANYEVENT_REDIS_DEBUG}; use AnyEvent; use AnyEvent::Handle; use AnyEvent::Socket; use AnyEvent::Redis::Protocol; use Carp qw( croak confess ); use Encode (); use Scalar::Util qw(weaken); our $AUTOLOAD; sub new { my ($class, %args) = @_; my $host = delete $args{host} || '127.0.0.1'; my $port = delete $args{port} || 6379; if (my $encoding = $args{encoding}) { $args{encoding} = Encode::find_encoding($encoding); croak qq{Encoding "$encoding" not found} unless ref $args{encoding}; } bless { host => $host, port => $port, pending_cvs => [], %args, }, $class; } sub run_cmd { my $self = shift; my $cmd = shift; $self->{cmd_cb} or return $self->connect($cmd, @_); $self->{cmd_cb}->($cmd, @_); } sub DESTROY { } sub AUTOLOAD { my $self = shift; (my $method = $AUTOLOAD) =~ s/.*:://; $self->run_cmd($method, @_); } sub all_cv { my $self = shift; $self->{all_cv} = shift if @_; $self->{all_cv} ||= AE::cv; } sub cleanup { my $self = shift; delete $self->{cmd_cb}; delete $self->{sock}; $self->{on_error}->(@_) if $self->{on_error}; $self->{on_cleanup}->(@_) if $self->{on_cleanup}; for (splice(@{$self->{pending_cvs}}), splice(@{$self->{multi_cvs} || []})) { eval { $_->croak(@_) }; warn "Exception in cleanup callback (ignored): $@" if $@; } return; } sub connect { my $self = shift; my $cv; if (@_) { $cv = pop if UNIVERSAL::isa($_[-1], 'AnyEvent::CondVar'); $cv ||= AE::cv; push @{$self->{connect_queue}}, [ $cv, @_ ]; } return $cv if $self->{sock}; weaken $self; $self->{sock} = tcp_connect $self->{host}, $self->{port}, sub { my $fh = shift or do { my $err = "Can't connect Redis server: $!"; $self->cleanup($err); eval { $cv->croak($err) }; warn "Exception in connect failure callback (ignored): $@" if $@; return }; binmode $fh; # ensure bytes until we decode my $hd = AnyEvent::Handle->new( fh => $fh, on_error => sub { $_[0]->destroy; $self->cleanup($_[2]) if $_[1]; }, on_eof => sub { $_[0]->destroy; $self->cleanup('connection closed'); }, encoding => $self->{encoding}, ); $self->{cmd_cb} = sub { my $command = lc shift; my $is_pubsub = $command =~ /^p?(?:un)?subscribe\z/; my $is_subscribe = $command =~ /^p?subscribe\z/; # Are we already subscribed to anything? if ($self->{sub} && %{$self->{sub}}) { croak "Use of non-pubsub command during pubsub session may result in unexpected behaviour" unless $is_pubsub; } # Are we already in a transaction? if ($self->{multi_write}) { croak "Use of pubsub or multi command in transaction is not supported" if $is_pubsub || $command eq 'multi'; } else { croak "Can't 'exec' a transaction because none is pending" if $command eq 'exec'; } my ($cv, $cb); if (@_) { $cv = pop if ref $_[-1] && UNIVERSAL::isa($_[-1], 'AnyEvent::CondVar'); $cb = pop if ref $_[-1] eq 'CODE'; } $cv ||= AE::cv; croak "Must provide a CODE reference for subscriptions" if $is_subscribe && !$cb; my $send = join("\r\n", "*" . (1 + @_), map { ('$' . length $_ => $_) } (uc($command), map { $self->{encoding} && length($_) ? $self->{encoding}->encode($_) : $_ } @_)) . "\r\n"; warn $send if DEBUG; # $self is weakened to avoid leaks, hold on to a strong copy # controlled via a CV. my $cmd_cv = AE::cv; $cmd_cv->cb(sub { my $strong_self = $self; }); # pubsub is very different - get it out of the way first if ($is_pubsub) { $hd->push_write($send); my $already = $self->{sub} && %{$self->{sub}}; if ($is_subscribe) { $self->{sub}->{$_} ||= [$cv, $cb] for @_; } if (!$already && @_) { my $res_cb; $res_cb = sub { $hd->push_read("AnyEvent::Redis::Protocol" => sub { my ($res, $err) = @_; if (ref $res) { my $action = lc $res->[0]; warn "$action $res->[1]" if DEBUG; if ($action eq 'message') { $self->{sub}->{$res->[1]}[1]->($res->[2], $res->[1]); } elsif ($action eq 'pmessage') { $self->{sub}->{$res->[1]}[1]->($res->[3], $res->[2], $res->[1]); } elsif ($action eq 'subscribe' || $action eq 'psubscribe') { $self->{sub_count} = $res->[2]; } elsif ($action eq 'unsubscribe' || $action eq 'punsubscribe') { $self->{sub_count} = $res->[2]; eval { $self->{sub}->{$res->[1]}[0]->send }; warn "Exception in callback (ignored): $@" if $@; delete $self->{sub}->{$res->[1]}; $self->all_cv->end; $cmd_cv->send; } else { warn "Unknown pubsub action: $action"; } } if ($self->{sub_count} || %{$self->{sub}}) { # Carry on reading while we are subscribed $res_cb->(); } }); }; $res_cb->(); } return $cv; } # non-pubsub from here on out $cv->cb(sub { my $cv = shift; local $@; eval { my $res = $cv->recv; $cb->($res); }; if ($@) { ($self->{on_error} || sub { die @_ })->(my $err = $@); } }) if $cb; $self->all_cv->begin; push @{$self->{pending_cvs}}, $cv; $hd->push_write($send); if ($command eq 'exec') { # at end of transaction, expect bulk reply possibly including errors $hd->push_read("AnyEvent::Redis::Protocol" => sub { my ($res, $err) = @_; $self->_expect($cv); my @mcvs = splice @{$self->{multi_cvs}}; if ($err || ref($res) ne 'ARRAY') { for ($cv, @mcvs) { eval { $_->croak($res, 1) }; warn "Exception in callback (ignored): $@" if $@; } } else { for my $i (0 .. $#mcvs) { my $r = $res->[$i]; eval { ref($r) && UNIVERSAL::isa($r, 'AnyEvent::Redis::Error') ? $mcvs[$i]->croak($$r) : $mcvs[$i]->send($r); }; warn "Exception in callback (ignored): $@" if $@; } eval { $cv->send($res) }; warn "Exception in callback (ignored): $@" if $@; } $self->all_cv->end; $cmd_cv->send; }); delete $self->{multi_write}; } elsif ($self->{multi_write}) { # in transaction, expect only "QUEUED" $hd->push_read("AnyEvent::Redis::Protocol" => sub { my ($res, $err) = @_; $self->_expect($cv); if (!$err && $res eq 'QUEUED') { push @{$self->{multi_cvs}}, $cv; } else { eval { $cv->croak($res) }; warn "Exception in callback (ignored): $@" if $@; } $self->all_cv->end; $cmd_cv->send; }); } else { $hd->push_read("AnyEvent::Redis::Protocol" => sub { my ($res, $err) = @_; $self->_expect($cv); if ($command eq 'info') { $res = { map { split /:/, $_, 2 } grep !/^#/, split /\r\n/, $res }; } elsif ($command eq 'keys' && !ref $res) { # Older versions of Redis (1.2) need this $res = [split / /, $res]; } eval { $err ? $cv->croak($res) : $cv->send($res) }; warn "Exception in callback (ignored): $@" if $@; $self->all_cv->end; $cmd_cv->send; }); $self->{multi_write} = 1 if $command eq 'multi'; } return $cv; }; my $queue = delete $self->{connect_queue} || []; for my $command (@$queue) { my($cv, @args) = @$command; $self->{cmd_cb}->(@args, $cv); } }; return $cv; } sub _expect { my ($self, $cv) = @_; my $p = shift @{$self->{pending_cvs} || []}; $p && $p == $cv or confess "BUG: mismatched CVs"; } 1; __END__ =encoding utf-8 =for stopwords =head1 NAME AnyEvent::Redis - Non-blocking Redis client =head1 SYNOPSIS use AnyEvent::Redis; my $redis = AnyEvent::Redis->new( host => '127.0.0.1', port => 6379, encoding => 'utf8', on_error => sub { warn @_ }, on_cleanup => sub { warn "Connection closed: @_" }, ); # callback based $redis->set( 'foo'=> 'bar', sub { warn "SET!" } ); $redis->get( 'foo', sub { my $value = shift } ); my ($key, $value) = ('list_key', 123); $redis->lpush( $key, $value ); $redis->lpop( $key, sub { my $value = shift }); # condvar based my $cv = $redis->lpop( $key ); $cv->cb(sub { my $value = $_[0]->recv }); =head1 DESCRIPTION AnyEvent::Redis is a non-blocking (event-driven) Redis client. This module is an AnyEvent user; you must install and use a supported event loop. =head1 ESTABLISHING A CONNECTION To create a new connection, use the new() method with the following attributes: =over =item host => B The hostname or literal address of the server. =item port => Optional. The server port. =item encoding => Optional. Encode and decode data (when storing and retrieving, respectively) according to I (C<"utf8"> is recommended or see L for details on possible I values). Omit if you intend to handle raw binary data with this connection. =item on_error => $cb->($errmsg) Optional. Callback that will be fired if a connection or database-level error occurs. The error message will be passed to the callback as the sole argument. =item on_cleanup => $cb->($errmsg) Optional. Callback that will be fired if a connection error occurs. The error message will be passed to the callback as the sole argument. After this callback, errors will be reported for all outstanding requests. =back =head1 METHODS All methods supported by your version of Redis should be supported. =head2 Normal commands There are two alternative approaches for handling results from commands: =over 4 =item * L based: my $cv = $redis->command( # arguments to command ); # Then... my $res; eval { # Could die() $res = $cv->recv; }; warn $@ if $@; # or... $cv->cb(sub { my ($cv) = @_; my ($result, $err) = $cv->recv }); =item * Callback: $redis->command( # arguments, sub { my ($result, $err) = @_; }); (Callback is a wrapper around the C<$cv> approach.) =back =head2 Transactions (MULTI/EXEC) Redis transactions begin with a "multi" command and end with an "exec" command. Commands in between are not executed immediately when they're sent. On receipt of the "exec", the server executes all the saved commands atomically, and returns all their results as one bulk reply. After a transaction is finished, results for each individual command are reported in the usual way. Thus, by the time any of these callbacks is called, the entire transaction is finished for better or worse. Results of the "exec" (containing all the other results) will be returned as an array reference containing all of the individual results. This may in some cases make callbacks on the individual commands unnecessary, or vice versa. In this bulk reply, errors reported for each individual command are represented by objects of class C, which will respond to a C<< ->message >> method call with that error message. It is not permitted to nest transactions. This module does not permit subscription-related commands in a transaction. =head2 Subscriptions The subscription methods (C and C) must be used with a callback: my $cv = $redis->subscribe("test", sub { my ($message, $channel[, $actual_channel]) = @_; # ($actual_channel is provided for pattern subscriptions.) }); The C<$cv> condition will be met on unsubscribing from the channel. Due to limitations of the Redis protocol the only valid commands on a connection with an active subscription are subscribe and unsubscribe commands. =head2 Common methods =over 4 =item * get =item * set =item * hset =item * hget =item * lpush =item * lpop =back The Redis command reference (L) lists all commands Redis supports. =head1 REQUIREMENTS This requires Redis >= 1.2. =head1 COPYRIGHT Tatsuhiko Miyagawa Emiyagawa@bulknews.netE 2009- =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHORS Tatsuhiko Miyagawa David Leadbeater Chia-liang Kao franck cuny Lee Aylward Joshua Barratt Jeremy Zawodny Leon Brocard Michael S. Fischer Chip Salzenberg =head1 SEE ALSO L, L =cut AnyEvent-Redis-0.24/META.yml0000644000175000001440000000115712062127517014201 0ustar dglusers--- abstract: 'Non-blocking Redis client' author: - 'Tatsuhiko Miyagawa' build_requires: ExtUtils::MakeMaker: 6.59 Test::More: 0 Test::TCP: 1.03 configure_requires: ExtUtils::MakeMaker: 6.59 distribution_type: module dynamic_config: 1 generated_by: 'Module::Install version 1.06' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: AnyEvent-Redis no_index: directory: - inc - t - xt requires: AnyEvent: 0 perl: 5.8.1 resources: license: http://dev.perl.org/licenses/ repository: git://github.com/miyagawa/AnyEvent-Redis version: 0.24 AnyEvent-Redis-0.24/.gitignore0000644000175000001440000000006111735272724014720 0ustar dglusersMETA.yml Makefile blib/ inc/ pm_to_blib *~ *.old AnyEvent-Redis-0.24/Makefile.PL0000644000175000001440000000037712036524033014700 0ustar dglusersuse inc::Module::Install; name 'AnyEvent-Redis'; all_from 'lib/AnyEvent/Redis.pm'; readme_from 'lib/AnyEvent/Redis.pm'; requires 'AnyEvent'; build_requires 'Test::More'; test_requires 'Test::TCP', 1.03; author_tests('xt'); auto_set_repository; WriteAll; AnyEvent-Redis-0.24/README0000644000175000001440000001171412062127517013610 0ustar dglusersNAME AnyEvent::Redis - Non-blocking Redis client SYNOPSIS use AnyEvent::Redis; my $redis = AnyEvent::Redis->new( host => '127.0.0.1', port => 6379, encoding => 'utf8', on_error => sub { warn @_ }, on_cleanup => sub { warn "Connection closed: @_" }, ); # callback based $redis->set( 'foo'=> 'bar', sub { warn "SET!" } ); $redis->get( 'foo', sub { my $value = shift } ); my ($key, $value) = ('list_key', 123); $redis->lpush( $key, $value ); $redis->lpop( $key, sub { my $value = shift }); # condvar based my $cv = $redis->lpop( $key ); $cv->cb(sub { my $value = $_[0]->recv }); DESCRIPTION AnyEvent::Redis is a non-blocking (event-driven) Redis client. This module is an AnyEvent user; you must install and use a supported event loop. ESTABLISHING A CONNECTION To create a new connection, use the new() method with the following attributes: host => Required. The hostname or literal address of the server. port => Optional. The server port. encoding => Optional. Encode and decode data (when storing and retrieving, respectively) according to *ENCODING* ("utf8" is recommended or see Encode::Supported for details on possible *ENCODING* values). Omit if you intend to handle raw binary data with this connection. on_error => $cb->($errmsg) Optional. Callback that will be fired if a connection or database-level error occurs. The error message will be passed to the callback as the sole argument. on_cleanup => $cb->($errmsg) Optional. Callback that will be fired if a connection error occurs. The error message will be passed to the callback as the sole argument. After this callback, errors will be reported for all outstanding requests. METHODS All methods supported by your version of Redis should be supported. Normal commands There are two alternative approaches for handling results from commands: * AnyEvent::CondVar based: my $cv = $redis->command( # arguments to command ); # Then... my $res; eval { # Could die() $res = $cv->recv; }; warn $@ if $@; # or... $cv->cb(sub { my ($cv) = @_; my ($result, $err) = $cv->recv }); * Callback: $redis->command( # arguments, sub { my ($result, $err) = @_; }); (Callback is a wrapper around the $cv approach.) Transactions (MULTI/EXEC) Redis transactions begin with a "multi" command and end with an "exec" command. Commands in between are not executed immediately when they're sent. On receipt of the "exec", the server executes all the saved commands atomically, and returns all their results as one bulk reply. After a transaction is finished, results for each individual command are reported in the usual way. Thus, by the time any of these callbacks is called, the entire transaction is finished for better or worse. Results of the "exec" (containing all the other results) will be returned as an array reference containing all of the individual results. This may in some cases make callbacks on the individual commands unnecessary, or vice versa. In this bulk reply, errors reported for each individual command are represented by objects of class "AnyEvent::Redis::Error", which will respond to a "->message" method call with that error message. It is not permitted to nest transactions. This module does not permit subscription-related commands in a transaction. Subscriptions The subscription methods ("subscribe" and "psubscribe") must be used with a callback: my $cv = $redis->subscribe("test", sub { my ($message, $channel[, $actual_channel]) = @_; # ($actual_channel is provided for pattern subscriptions.) }); The $cv condition will be met on unsubscribing from the channel. Due to limitations of the Redis protocol the only valid commands on a connection with an active subscription are subscribe and unsubscribe commands. Common methods * get * set * hset * hget * lpush * lpop The Redis command reference () lists all commands Redis supports. REQUIREMENTS This requires Redis >= 1.2. COPYRIGHT Tatsuhiko Miyagawa 2009- LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHORS Tatsuhiko Miyagawa David Leadbeater Chia-liang Kao franck cuny Lee Aylward Joshua Barratt Jeremy Zawodny Leon Brocard Michael S. Fischer Chip Salzenberg SEE ALSO Redis, AnyEvent