| 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'}
MC/DC0%0/2
shift() || $obj->{'-file'}
shift()
$obj->{'-file'}
Truth table0%0/3
A || B
A= shift()B= $obj->{'-file'}
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | open F,$file or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | ▶ | while (<F>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | chomp; | |||||||||||||||||||
| 52 | 0 | s/#.*$//; s/\s+$//; s/^\s+//; | |||||||||||||||||||
| 53 | 0 | ▶ | next unless $_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | ▶ | next if /^:/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 0 | ▶ | next if /^\|/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | ▶ | next if /^all:/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | ▶ | if (/^include (.*)/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||