File Coverage

blib/lib/Term/GnuScreen.pm
Criterion Covered Total %
statement 26 59 44.0
branch 0 22 0.0
condition n/a
subroutine 7 14 50.0
pod 3 4 75.0
total 36 99 36.3


line stmt bran cond sub pod time code
1             package Term::GnuScreen;
2              
3 1     1   25170 use Moo;
  1         27329  
  1         7  
4 1     1   3688 use File::Temp qw(tmpnam);
  1         59285  
  1         100  
5 1     1   922 use autodie qw(:all);
  1         44156  
  1         7  
6 1     1   26663 use File::Which;
  1         1269  
  1         64  
7 1     1   769 use IO::CaptureOutput qw(capture);
  1         2198  
  1         89  
8              
9             our $VERSION = '0.05';
10              
11             BEGIN {
12              
13 1     1   6 no strict 'refs';
  1         2  
  1         346  
14              
15 1     1   30 my @commands = ( qw( acladd aclchg acldel aclgrp aclumask activity addacl allpartial
16             altscreen at attrcolor autodetach autonuke backtick bce bell_msg
17             bindkey blanker blankerprg break breaktype bufferfile c1 caption chacl
18             charset clear colon command compacthist console copy copy_reg
19             crlf debug defautonuke defbce defbreaktype defc1 defcharset defencoding
20             defescape defflow defgr defhstatus deflog deflogin defmode defmonitor
21             defnonblock defobuflimit defscrollback defshell defsilence defslowpaste
22             defutf8 defwrap defwritelock defzombie detach digraph dinfo displays
23             dumptermcap echo encoding escape eval fit flow focus gr
24             hardcopy_append hardcopydir hardstatus height help history hstatus idle
25             ignorecase info ins_reg lastmsg license lockscreen log logfile login
26             logtstamp mapdefault mapnotnext maptimeout markkeys maxwin monitor
27             msgminwait msgwait multiuser nethack next nonblock number obuflimit only
28             other partial password paste pastefont pow_break pow_detach pow_detach_msg
29             prev printcmd process quit readbuf readreg redisplay register remove
30             removebuf reset resize screen scrollback select sessionname setenv setsid
31             shell shelltitle silence silencewait sleep slowpaste source sorendition
32             split startup_message stuff su suspend term termcap terminfo termcapinfo
33             time title unsetenv utf8 vbell vbell_msg vbellwait version wall
34             width windowlist windows wrap writebuf writelock xoff xon zmodem zombie ) );
35              
36 1         4 for my $name (@commands) {
37 167     0   806 *{__PACKAGE__ . "::$name"} = sub { shift->send_command($name,@_) }
  0         0  
38 167         522 }
39              
40 1         5 my @rcommands = ( qw( bind kill meta chdir exec umask) );
41              
42 1         2 for my $name (@rcommands) {
43 6     0   1424 *{__PACKAGE__ . "::s$name"} = sub { shift->send_command($name,@_) }
  0            
44 6         14 }
45             }
46              
47             has session => (is => 'rw' );
48             has window => (is => 'rw', default => sub { 0 } );
49             has executable => (is => 'rw', default => sub { which("screen") } );
50             has create => (is => 'ro', default => sub { 0 } );
51             has debugging => (is => 'rw', default => sub { 0 } );
52              
53             sub BUILD {
54 0     0 0   my ($self) = @_;
55 0 0         if ($self->create) {
56 0 0         if (!$self->session) {
57 0           $self->session("term_gnuscreen.$$" . int(rand(10000)));
58             }
59 0           $self->call_screen('-m','-d');
60             }
61 0           return;
62             }
63              
64             sub send_command {
65 0     0 1   my ($self,$cmd,@args) = @_;
66 0 0         die "No command supplied while trying to call screen via -X."
67             if !$cmd;
68 0 0         return $self->call_screen('-X', $cmd, @args) if $cmd;
69             }
70              
71             sub call_screen {
72 0     0 1   my ($self,@parameter) = @_;
73 0           my @screencmd = ( $self->executable );
74 0 0         push @screencmd, '-S', $self->session if defined $self->session;
75 0 0         push @screencmd, '-p', $self->window if defined $self->window;
76 0           push @screencmd, @parameter;
77              
78 0 0         if ($self->debugging) {
79 0           print STDERR "Command: " . join(" ",@screencmd) . "\n";
80             }
81              
82 0           my ($stdout,$stderr);
83             eval {
84 0     0     capture { system(@screencmd) } \$stdout, \$stderr;
  0            
85 0           1;
86 0 0         } or do {
87 0           my $err;# = $!;
88 0 0         $err = $stderr if defined $stderr;
89 0 0         $err = $stdout if defined $stdout; # '*err*, stdout seems to be actual more helpful
90 0           die "$err";
91             };
92 0           return 1;
93             }
94              
95             sub hardcopy {
96 0     0 1   my ($self,$file) = @_;
97 0 0         if (!$file) {
98 0           $file = tmpnam();
99             }
100 0           $self->send_command('hardcopy',$file);
101 0           return $file;
102             }
103              
104             1;
105              
106             __END__