Print/Printcap.pm

filter: Statementstmt 21.0% 8 / 38 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 2 / 5 Podpod 66.6% 2 / 3 totaltotal 18.4% 12 / 65 CC 10 SCAR 40.8
CC
10
Cov
15%
parse_printcap
90.0
new
6.0
printers
2.0
CRAP 59.0
« PostScript/Poster.pm ↑ Summary DBIx/SystemCatalog.pm »
1 package Print::Printcap;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 $VERSION = '0.01';
7  
8 =head1 NAME
9  
10 Hints - Perl extension for parsing /etc/printcap
11  
12 =head1 SYNOPSIS
13  
14 use Print::Printcap;
15  
16 my $printcap = new Print::Printcap;
17  
18 print join ',',$printcap->printers();
19  
20 =head1 DESCRIPTION
21  
22 Simple parser for /etc/printcap.
23  
24 =head1 THE PRINT::PRINTCAP CLASS
25  
26 =head2 new
27  
28 Constructor create instance of Print::Printcap class and parse /etc/printcap.
29 Optional argument is -file => 'filename' for specifying alternate printcap
30 file.
31  
32 my $printcap = new Print::Printcap;
33  
34 =cut
35  
36 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
37 0 my $class = shift;
38 0 my $obj = bless { -file => '/etc/printcap', printers => [] }, $class;
39 0 my %par = @_;
40 0 for (keys %par) { $obj->{$_} = $par{$_}; }
41 0 $obj->parse_printcap;
42 0 return $obj;
43 }
44  
45 0 ▶sub parse_printcap {
Subroutine parse_printcap: not called CC=9 SCAR=45.0
Pod undocumented
46 0 my $obj = shift;
47 0 ▶ my $file = shift || $obj->{-file};
Condition0%0/3
shift() || $obj->{'-file'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $obj->{'-file'}
shift() $obj->{'-file'}
Truth table0%0/3
A || B
A= shift()B= $obj->{'-file'}
ABresult
1X1
011
000
48  
49 0 ▶ open F,$file or return;
Branch: 1 branch
BranchTrueFalseTotal
open F, $file or return 0 0 0
50 0 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 0 0 0
51 0 chomp;
52 0 s/#.*$//; s/\s+$//; s/^\s+//;
53 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
54 0 ▶ next if /^:/;
Branch: 1 branch
BranchTrueFalseTotal
if /^:/ 0 0 0
55 0 ▶ next if /^\|/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\|/ 0 0 0
56 0 ▶ next if /^all:/;
Branch: 1 branch
BranchTrueFalseTotal
if /^all:/ 0 0 0
57 0 ▶ if (/^include (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^include (.*)/) 0 0 0
58 0 $obj->parse_printcap($_);
59 0 next;
60 }
61 0 s/:.*$//; s/\|.*$//;
62 0 push @{$obj->{printers}},$_;
63 }
64 0 close F;
65 }
66  
67 =head2 printers
68  
69 Return list of printers from /etc/printcap.
70  
71 my @printers = $printcap->printers();
72  
73 =cut
74  
75 0 ▶sub printers {
Subroutine printers: not called CC=1 SCAR=6.9
Pod documented
76 0 my $obj = shift;
77 0 return @{$obj->{printers}};
78 }
79  
80 1 1;
81  
82 __END__
« PostScript/Poster.pm ↑ Summary DBIx/SystemCatalog.pm »