File Coverage

lib/App/assh.pm
Criterion Covered Total %
statement 35 66 53.0
branch 0 6 0.0
condition n/a
subroutine 15 19 78.9
pod n/a
total 50 91 54.9


line stmt bran cond sub pod time code
1             package App::assh;
2             BEGIN {
3 1     1   45874 $App::assh::AUTHORITY = 'cpan:DBR';
4             }
5             {
6             $App::assh::VERSION = '1.1.2';
7             }
8              
9             # PODNAME: App::assh
10             # ABSTRACT: A wrapper around autossh.
11              
12 1     1   1076 use Moo;
  1         46648  
  1         8  
13 1     1   2879 use true;
  1         21411  
  1         8  
14 1     1   1542 use 5.010;
  1         4  
  1         47  
15 1     1   7 use strict;
  1         1  
  1         51  
16 1     1   6 use warnings;
  1         3  
  1         47  
17 1     1   955 use methods-invoker;
  1     1   95061  
  1         8  
  1         5769  
  1         13698  
  1         10  
18 1     1   1178 use MooX::Options skip_options => [qw];
  1         1808  
  1         52  
19 1     1   399416 use MooX::Types::MooseLike::Base qw(:all);
  1         7469  
  1         484  
20              
21             has hosts => (
22             is => 'lazy',
23             isa => HashRef,
24             );
25              
26             has ports => (
27             is => 'lazy',
28             isa => HashRef,
29             );
30              
31             has ssh_config_file => (
32             is => 'ro',
33             isa => Str,
34             default => sub {
35             "$ENV{HOME}/.ssh/config"
36             },
37             );
38              
39             has ports_config_file => (
40             is => 'ro',
41             isa => Str,
42             default => sub {
43             "$ENV{HOME}/.autossh_rc"
44             },
45             );
46              
47 1     1   1084 method _build_hosts {
  0     0      
  0            
48 0           $_ = do { local(@ARGV, $/) = $->ssh_config_file; <>; };
  0            
  0            
49 0           s/\s+/ /g;
50              
51 0           my $ret = {};
52 0           while (mxg) {
53 0           $ret->{$1} = { NAME => $2, USER => $3 }
54             }
55              
56 0           return $ret;
57             }
58              
59 1     1   699 method _build_ports {
  0     0      
  0            
60 0 0         open my $portsfile, "<", $->ports_config_file or die $!;
61 0           my $h = {};
62 0           while(<$portsfile>) {
63 0           chomp;
64 0           my ($host, $port) = split;
65 0           $h->{$host} = $port;
66             }
67 0           return $h
68             }
69              
70 1     1   536 method run {
  0     0      
  0            
71 0           my $host = shift;
72              
73 0 0         not defined $host and do {
74 0           say for keys %{$->hosts};
  0            
75             };
76              
77 0 0         defined $->hosts->{$host} and do {
78 0           $->autossh_exec($host);
79             };
80             }
81              
82 1     1   478 method autossh_exec {
  0     0      
  0            
83 0           my $host = shift;
84 0           exec 'AUTOPOLL=5 autossh -M ' . $->ports->{$host} . ' ' . $->hosts->{$host}{USER} . '@' . $->hosts->{$host}{NAME}
85             }
86              
87 1     1   268 no Moo;
  1         2  
  1         7  
88              
89             __END__