X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTak.pm;h=65a6153794018d85bf3d4ec31e9842aee8143afa;hb=fb0f5964bfe05daa3f82ec9261cfc0bb9d181223;hp=1e0de481de45e31445b1ef5a7c0ccc5317873c55;hpb=934a93db8e9fb542f0fe15ced85f932ee562885f;p=scpubgit%2FTak.git diff --git a/lib/Tak.pm b/lib/Tak.pm index 1e0de48..65a6153 100644 --- a/lib/Tak.pm +++ b/lib/Tak.pm @@ -3,15 +3,25 @@ package Tak; use Tak::Loop; use strictures 1; -our $loop; +our $VERSION = '0.001001'; # 0.1.1 + +our ($loop, $did_upgrade); sub loop { $loop ||= Tak::Loop->new } +sub loop_upgrade { + return if $did_upgrade; + require IO::Async::Loop; + my $new_loop = IO::Async::Loop->new; + $loop->pass_watches_to($new_loop) if $loop; + $loop = $new_loop; + $did_upgrade = 1; +} + sub loop_until { my ($class, $done) = @_; return if $done; - my $loop = $class->loop; - $loop->loop_once until $_[1]; + $class->loop->loop_once until $_[1]; } sub await_all { @@ -20,16 +30,76 @@ sub await_all { return unless @requests; my %req = map +("$_" => "$_"), @requests; my $done; - my %orig; my %on_r = map { - my $orig = $orig{$_} = $_->{on_result}; + my $orig = $_->{on_result}; my $tag = $req{$_}; ($_ => sub { delete $req{$tag}; $orig->(@_); $done = 1 unless keys %req; }) } @requests; - $_->{on_result} = $on_r{$_} for @requests; - $class->loop_until($done); - $_->{on_result} = $orig{$_} for @requests; + my $call = sub { $class->loop_until($done) }; + foreach (@requests) { + my $req = $_; + my $inner = $call; + $call = sub { local $req->{on_result} = $on_r{$req}; $inner->() }; + } + $call->(); return; } -1; +"for lexie"; + +=head1 NAME + +Tak - Multi host remote control over ssh + +=head1 SYNOPSIS + + bin/tak -h user1@host1 -h user2@host2 exec cat /etc/hostname + +or + + in Takfile: + + package Tak::MyScript; + + use Tak::Takfile; + use Tak::ObjectClient; + + sub each_get_homedir { + my ($self, $remote) = @_; + my $oc = Tak::ObjectClient->new(remote => $remote); + my $home = $oc->new_object('Path::Class::Dir')->absolute->stringify; + $self->stdout->print( + $remote->host.': '.$home."\n" + ); + } + + 1; + +then + + tak -h something get-homedir + +=head1 WHERE'S THE REST? + +A drink leaked in my bag on the way back from LPW. You'll get more once I +get my laptop's drive into an enclosure and decant the slides. + +=head1 AUTHOR + +mst - Matt S. Trout (cpan:MSTROUT) + +=head1 CONTRIBUTORS + +None required yet. Maybe this module is perfect (hahahahaha ...). + +=head1 COPYRIGHT + +Copyright (c) 2011 the strictures L and L +as listed above. + +=head1 LICENSE + +This library is free software and may be distributed under the same terms +as perl itself. + +=cut