Tak.pm

filter: Statementstmt 21.9% 9 / 41 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 4 totaltotal 15.4% 11 / 71 SCAR 40.4
CC
9
Cov
16%
loop_upgrade
12.0
loop_until
12.0
await_all
12.0
CRAP 56.9
« Tak/JSONChannel.pm ↑ Summary Tak/MetaService.pm »
1 package Tak;
2  
3 1 ▶use Tak::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.001003'; # 0.1.3
7  
8 1 our ($loop, $did_upgrade);
9  
10 0 ▶sub loop { $loop ||= Tak::Loop->new }
Subroutine loop: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
$Tak::loop ||= "Tak::Loop"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$Tak::loop ||= "Tak::Loop"->new
$Tak::loop "Tak::Loop"->new
Truth table0%0/3
A ||= B
A= $Tak::loopB= "Tak::Loop"->new
ABresult
1X1
011
000
11  
12 sub loop_upgrade {
13 0 ▶ return if $did_upgrade;
Subroutine loop_upgrade: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $Tak::did_upgrade 0 0 0
14 0 require IO::Async::Loop;
15 0 my $new_loop = IO::Async::Loop->new;
16 0 ▶ $loop->pass_watches_to($new_loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $Tak::loop 0 0 0
17 0 $loop = $new_loop;
18 0 $did_upgrade = 1;
19 }
20  
21 sub loop_until {
22 0 ▶ my ($class, $done) = @_;
Subroutine loop_until: not called CC=3 SCAR=24.8
Pod undocumented
23 0 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
24 0 ▶ $class->loop->loop_once until $_[1];
Branch: 1 branch
BranchTrueFalseTotal
$_[1] or do { $class->loop->loop_once } 0 0 0
25 }
26  
27 sub await_all {
28 0 ▶ my ($class, @requests) = @_;
Subroutine await_all: not called CC=3 SCAR=24.8
Pod undocumented
29 0 @requests = grep !$_->is_done, @requests;
30 0 ▶ return unless @requests;
Branch: 1 branch
BranchTrueFalseTotal
unless @requests 0 0 0
31 0 my %req = map +("$_" => "$_"), @requests;
32 0 my $done;
33 my %on_r = map {
34 0 my $orig = $_->{on_result};
35 0 my $tag = $req{$_};
36 0 ▶ ($_ => sub { delete $req{$tag}; $orig->(@_); $done = 1 unless keys %req; })
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless keys %req 0 0 0
37 0 } @requests;
38 0 ▶ my $call = sub { $class->loop_until($done) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 foreach (@requests) {
40 0 my $req = $_;
41 0 my $inner = $call;
42 0 ▶ $call = sub { local $req->{on_result} = $on_r{$req}; $inner->() };
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 }
44 0 $call->();
45 0 return;
46 }
47  
48 1 1;
49  
50 =head1 NAME
51  
52 Tak - Multi host remote control over ssh
53  
54 =head1 SYNOPSIS
55  
56 bin/tak -h user1@host1 -h user2@host2 exec cat /etc/hostname
57  
58 or
59  
60 in Takfile:
61  
62 package Tak::MyScript;
63
64 use Tak::Takfile;
65 use Tak::ObjectClient;
66
67 sub each_get_homedir {
68 my ($self, $remote) = @_;
69 my $oc = Tak::ObjectClient->new(remote => $remote);
70 my $home = $oc->new_object('Path::Class::Dir')->absolute->stringify;
71 $self->stdout->print(
72 $remote->host.': '.$home."\n"
73 );
74 }
75
76 1;
77  
78 then
79  
80 tak -h something get-homedir
81  
82 =head1 WHERE'S THE REST?
83  
84 A drink leaked in my bag on the way back from LPW. My laptop is finally
85 alive again though so I'll try and turn my slides into a vague attempt
86 at documentation while I'm traveling to/from christmas things.
87  
88 =head1 AUTHOR
89  
90 mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
91  
92 =head1 CONTRIBUTORS
93  
94 None required yet. Maybe this module is perfect (hahahahaha ...).
95  
96 =head1 COPYRIGHT
97  
98 Copyright (c) 2011 the Tak L</AUTHOR> and L</CONTRIBUTORS>
99 as listed above.
100  
101 =head1 LICENSE
102  
103 This library is free software and may be distributed under the same terms
104 as perl itself.
105  
106 =cut
« Tak/JSONChannel.pm ↑ Summary Tak/MetaService.pm »