blib/lib/IO/Tty.pm

filter: Statementstmt 84.2% 64 / 76 Branchbran 50.0% 11 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 5 totaltotal 72.9% 89 / 122 CC 12 SCAR 12.9
CC
12
Cov
75%
clone_winsize_from
6.3
set_raw
6.0
open
6.0
CRAP 3.6
« blib/lib/IO/Pty.pm ↑ Summary Tty.xs »
1 # Documentation at the __END__
2 # -*-cperl-*-
3  
4 package IO::Tty;
5  
6 11 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use IO::Tty::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 require POSIX;
16  
17 11 our @ISA = qw(IO::Handle);
18 11 our $VERSION = '1.29';
19 11 our ( $CONFIG, $DEBUG );
20  
21 11 eval { local $^W = 0; local $SIG{__DIE__}; require IO::Stty };
22 11 ▶push @ISA, "IO::Stty" if ( not $@ ); # if IO::Stty is installed
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 11 11
23  
24 11 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 XSLoader::load(__PACKAGE__, $VERSION);
26  
27 sub import {
28 14 ▶ IO::Tty::Constant->export_to_level( 1, @_ );
Subroutine import: called CC=1 SCAR=0.0
29 }
30  
31 sub open {
32 0 ▶ my ( $tty, $dev, $mode ) = @_;
Subroutine open: not called CC=2 SCAR=17.9
Pod undocumented
33  
34 0 ▶ IO::File::open( $tty, $dev, $mode )
Branch: 1 branch
BranchTrueFalseTotal
IO::File::open($tty, $dev, $mode) or return undef 0 0 0
35 or return undef;
36  
37 0 $tty->autoflush;
38  
39 0 1;
40 }
41  
42 sub clone_winsize_from {
43 3 ▶ my ( $self, $fh ) = @_;
Subroutine clone_winsize_from: called CC=5 SCAR=18.4
Pod undocumented
44 3 ▶ croak "Given filehandle is not a tty in clone_winsize_from, called"
Branch: 1 branch
BranchTrueFalseTotal
unless POSIX::isatty($fh) 1 2 3
45 if not POSIX::isatty($fh);
46 2 ▶ return 1 if not POSIX::isatty($self); # ignored for master ptys
Branch: 1 branch
BranchTrueFalseTotal
unless POSIX::isatty($self) 0 2 2
47 2 my $winsize = IO::Tty::pack_winsize( 0, 0, 0, 0 );
48 2 ▶ ioctl( $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize )
Branch: 1 branch
BranchTrueFalseTotal
ioctl $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize and ioctl $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize and return 1 2 0 2
Condition33%1/3
ioctl $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize and ioctl $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize
!ll&&!rl&&r
002
MC/DC0%0/2
ioctl $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize and ioctl $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize
ioctl $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize ioctl $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize
Truth table33%1/3
A and B
A= ioctl $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsizeB= ioctl $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize
ABresult
0X0
100
111
49 and ioctl( $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize )
50 and return 1;
51 0 carp "clone_winsize_from: error: $!";
52 0 return undef;
53 }
54  
55 # ioctl() may pad the buffer beyond sizeof(struct winsize),
56 # so trim it before passing to unpack_winsize.
57 11 my $SIZEOF_WINSIZE = length IO::Tty::pack_winsize( 0, 0, 0, 0 );
58  
59 sub get_winsize {
60 5 ▶ my $self = shift;
Subroutine get_winsize: called CC=2 SCAR=7.0
Pod undocumented
61 5 my $winsize = IO::Tty::pack_winsize( 0, 0, 0, 0 );
62 5 ▶ ioctl( $self, IO::Tty::Constant::TIOCGWINSZ(), $winsize )
Branch: 1 branch
BranchTrueFalseTotal
ioctl $self, &IO::Tty::Constant::TIOCGWINSZ(), $winsize or croak("Cannot TIOCGWINSZ - $!") 0 5 5
63 or croak "Cannot TIOCGWINSZ - $!";
64 5 substr( $winsize, $SIZEOF_WINSIZE ) = "";
65 5 return IO::Tty::unpack_winsize($winsize);
66 }
67  
68 sub set_winsize {
69 3 ▶ my $self = shift;
Subroutine set_winsize: called CC=2 SCAR=7.1
Pod undocumented
70 3 my $winsize = IO::Tty::pack_winsize(@_);
71 3 ▶ ioctl( $self, IO::Tty::Constant::TIOCSWINSZ(), $winsize )
Branch: 1 branch
BranchTrueFalseTotal
ioctl $self, &IO::Tty::Constant::TIOCSWINSZ(), $winsize or croak("Cannot TIOCSWINSZ - $!") 0 3 3
72 or croak "Cannot TIOCSWINSZ - $!";
73 }
74  
75 sub set_raw($) {
76 4 ▶ require POSIX;
Subroutine set_raw: called CC=5 SCAR=18.0
Pod undocumented
77 4 my $self = shift;
78 4 ▶ return 1 if not POSIX::isatty($self);
Branch: 1 branch
BranchTrueFalseTotal
unless POSIX::isatty($self) 0 4 4
79 4 my $ttyno = fileno($self);
80 4 my $termios = POSIX::Termios->new;
81 4 ▶ unless ($termios) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($termios) 0 4 4
82 0 warn "set_raw: new POSIX::Termios failed: $!";
83 0 return undef;
84 }
85 4 ▶ unless ( $termios->getattr($ttyno) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($termios->getattr($ttyno)) 0 4 4
86 0 warn "set_raw: getattr($ttyno) failed: $!";
87 0 return undef;
88 }
89 4 $termios->setiflag(0);
90 4 $termios->setoflag(0);
91 4 $termios->setlflag(0);
92 4 $termios->setcflag(
93 ( $termios->getcflag() & ~( &POSIX::CSIZE | &POSIX::PARENB ) )
94 | &POSIX::CS8
95 );
96 4 $termios->setcc( &POSIX::VMIN, 1 );
97 4 $termios->setcc( &POSIX::VTIME, 0 );
98 4 ▶ unless ( $termios->setattr( $ttyno, &POSIX::TCSANOW ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($termios->setattr($ttyno, &POSIX::TCSANOW)) 0 4 4
99 0 warn "set_raw: setattr($ttyno) failed: $!";
100 0 return undef;
101 }
102 4 return 1;
103 }
104  
105 11 1;
106  
107 __END__
« blib/lib/IO/Pty.pm ↑ Summary Tty.xs »