line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Print::Printcap; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
717
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
489
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub new { |
37
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
38
|
0
|
|
|
|
|
|
my $obj = bless { -file => '/etc/printcap', printers => [] }, $class; |
39
|
0
|
|
|
|
|
|
my %par = @_; |
40
|
0
|
|
|
|
|
|
for (keys %par) { $obj->{$_} = $par{$_}; } |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$obj->parse_printcap; |
42
|
0
|
|
|
|
|
|
return $obj; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub parse_printcap { |
46
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
47
|
0
|
|
0
|
|
|
|
my $file = shift || $obj->{-file}; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
open F,$file or return; |
50
|
0
|
|
|
|
|
|
while () { |
51
|
0
|
|
|
|
|
|
chomp; |
52
|
0
|
|
|
|
|
|
s/#.*$//; s/\s+$//; s/^\s+//; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
next unless $_; |
54
|
0
|
0
|
|
|
|
|
next if /^:/; |
55
|
0
|
0
|
|
|
|
|
next if /^\|/; |
56
|
0
|
0
|
|
|
|
|
next if /^all:/; |
57
|
0
|
0
|
|
|
|
|
if (/^include (.*)/) { |
58
|
0
|
|
|
|
|
|
$obj->parse_printcap($_); |
59
|
0
|
|
|
|
|
|
next; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
s/:.*$//; s/\|.*$//; |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
push @{$obj->{printers}},$_; |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub printers { |
76
|
0
|
|
|
0
|
1
|
|
my $obj = shift; |
77
|
0
|
|
|
|
|
|
return @{$obj->{printers}}; |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |