Perl.pm

filter: Statementstmt 43.4% 10 / 23 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 1 / 4 Podpod 100% 2 / 2 totaltotal 28.2% 13 / 46 SCAR 35.1
CC
8
Cov
26%
_winsize
20.0
chars
12.0
pixels
12.0
CRAP 33.6
↑ Summary Perl/Params.pm »
1  
2 package Term::Size::Perl;
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 require Exporter;
7  
8 2 our @ISA = qw(Exporter);
9 2 our @EXPORT_OK = qw(chars pixels);
10  
11 2 our $VERSION = '0.030_0';
12  
13 =head1 NAME
14  
15 Term::Size::Perl - Perl extension for retrieving terminal size (Perl version)
16  
17 =head1 SYNOPSIS
18  
19 use Term::Size::Perl;
20  
21 ($columns, $rows) = Term::Size::Perl::chars *STDOUT{IO};
22 ($x, $y) = Term::Size::Perl::pixels;
23  
24 =head1 DESCRIPTION
25  
26 Yet another implementation of C<Term::Size>. Now
27 in pure Perl, with the exception of a C probe run
28 on build time.
29  
30 =head2 FUNCTIONS
31  
32 =over 4
33  
34 =item B<chars>
35  
36 ($columns, $rows) = chars($h);
37 $columns = chars($h);
38  
39 C<chars> returns the terminal size in units of characters
40 corresponding to the given filehandle C<$h>.
41 If the argument is omitted, C<*STDIN{IO}> is used.
42 In scalar context, it returns the terminal width.
43  
44 =item B<pixels>
45  
46 ($x, $y) = pixels($h);
47 $x = pixels($h);
48  
49 C<pixels> returns the terminal size in units of pixels
50 corresponding to the given filehandle C<$h>.
51 If the argument is omitted, C<*STDIN{IO}> is used.
52 In scalar context, it returns the terminal width.
53  
54 Many systems with character-only terminals will return C<(0, 0)>.
55  
56 =back
57  
58 =head1 SEE ALSO
59  
60 It all began with L<Term::Size> by Tim Goodwin. You may want to
61 have a look at:
62  
63 L<Term::Size>
64  
65 L<Term::Size::Unix>
66  
67 L<Term::Size::Win32>
68  
69 L<Term::Size::ReadKey>
70  
71 Please reports bugs via GitHub,
72 https://github.com/aferreira/cpan-Term-Size-Perl/issues
73 When reporting bugs, it may be helpful to attach the F<Params.pm> generated by
74 the probe at build time.
75  
76 =head1 AUTHOR
77  
78 Adirano Ferreira, E<lt>ferreira@cpan.orgE<gt>
79  
80 =head1 COPYRIGHT AND LICENSE
81  
82 Copyright (C) 2006-2007, 2017-2018 by Adriano Ferreira
83  
84 This library is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself.
86  
87 =cut
88  
89 2 require Term::Size::Perl::Params;
90 2 my %params = Term::Size::Perl::Params::params();
91  
92 # ( row, col, x, y )
93 sub _winsize {
94 0 ▶ my $h = shift || *STDIN;
Subroutine _winsize: not called CC=4 SCAR=30.0
Condition0%0/3
shift() || *STDIN
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || *STDIN
shift() *STDIN
Truth table0%0/3
A || B
A= shift()B= *STDIN
ABresult
1X1
011
000
95 0 ▶ return unless -t $h;
Branch: 1 branch
BranchTrueFalseTotal
unless -t $h 0 0 0
96 0 my $sz = "\0" x $params{winsize}{sizeof};
97 0 ▶ ioctl($h, $params{TIOCGWINSZ}{value}, $sz)
Branch: 1 branch
BranchTrueFalseTotal
ioctl $h, $params{"TIOCGWINSZ"}{"value"}, $sz or return 0 0 0
98 or return;
99 0 return unpack $params{winsize}{mask}, $sz;
100 }
101  
102 sub chars {
103 0 ▶ my @sz = _winsize(shift);
Subroutine chars: not called CC=3 SCAR=24.8
Pod documented
104 0 ▶ return unless @sz;
Branch: 1 branch
BranchTrueFalseTotal
unless @sz 0 0 0
105 0 ▶ return @sz[1, 0] if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
106 0 return $sz[1];
107 }
108  
109 sub pixels {
110 0 ▶ my @sz = _winsize(shift);
Subroutine pixels: not called CC=3 SCAR=24.8
Pod documented
111 0 ▶ return unless @sz;
Branch: 1 branch
BranchTrueFalseTotal
unless @sz 0 0 0
112 0 ▶ return @sz[2, 3] if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
113 0 return $sz[2];
114 }
115  
116 2 1;
↑ Summary Perl/Params.pm »