| 1 | #! /usr/bin/perl -w | ||||||||||||||||||||||||||||
| 2 | ################################################################################ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # File.pm (do cool things with files) | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | ################################################################################ | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # Package | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | ################################################################################ | ||||||||||||||||||||||||||||
| 11 | package PML::File; | ||||||||||||||||||||||||||||
| 12 | ################################################################################ | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # Includes | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | ################################################################################ | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | ################################################################################ | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | # Global Variables and Default Settings | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | ################################################################################ | ||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use vars qw($VERSION $DATE $ID); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 25 | 1 | $DATE = 'Wed May 24 16:58:17 2000'; | |||||||||||||||||||||||||||
| 26 | 1 | $ID = '$Id: File.pm,v 1.4 2000/07/31 17:13:46 pjones Exp $'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | my $pkg = 'file::'; | |||||||||||||||||||||||||||
| 29 | 1 | my $local = "${pkg}local"; | |||||||||||||||||||||||||||
| 30 | 1 | my $prefix = "${pkg}prefix"; | |||||||||||||||||||||||||||
| 31 | 1 | my $dprefix = 'conf'; | |||||||||||||||||||||||||||
| 32 | ################################################################################ | ||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||
| 34 | # Code Start | ||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||
| 36 | ################################################################################ | ||||||||||||||||||||||||||||
| 37 | 1 | PML->register(name=>"${pkg}cat", token=>\&cat); | |||||||||||||||||||||||||||
| 38 | 1 | PML->register(name=>"${pkg}conf",token=>\&conf); | |||||||||||||||||||||||||||
| 39 | ################################################################################ | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | # ==== cat ==== ################################################################ | ||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||
| 43 | # Arguments: | ||||||||||||||||||||||||||||
| 44 | # See PML Docs | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | # Returns: | ||||||||||||||||||||||||||||
| 47 | # The contents of the files | ||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||
| 49 | # Description: | ||||||||||||||||||||||||||||
| 50 | # Returns the contents of a bunch of files | ||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||
| 52 | ################################################################################ | ||||||||||||||||||||||||||||
| 53 | sub cat | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
cat: called CC=4 SCAR=15.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 1 | my ($self, $token) = @_; | |||||||||||||||||||||||||||
| 56 | 1 | my ($name, $a, $b) = @{$token->data}; | |||||||||||||||||||||||||||
| 57 | 1 | my (@files, $file, $result); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | @files = $self->tokens_execute($a); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | foreach $file (@files) { | |||||||||||||||||||||||||||
| 62 | 1 | ▶ | unless (open CAT, $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($self->warning) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | print STDERR "can't open file '$file': $!\n"; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | next; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | $result .= join '', <CAT>; | |||||||||||||||||||||||||||
| 70 | 1 | close CAT; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | return $result; | |||||||||||||||||||||||||||
| 74 | } # <-- End cat --> | ||||||||||||||||||||||||||||
| 75 | ################################################################################ | ||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||
| 77 | # ==== conf ==== ############################################################### | ||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | # Arguments: | ||||||||||||||||||||||||||||
| 80 | # See PML Docs | ||||||||||||||||||||||||||||
| 81 | # | ||||||||||||||||||||||||||||
| 82 | # Returns: | ||||||||||||||||||||||||||||
| 83 | # Nothing | ||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||
| 85 | # Description: | ||||||||||||||||||||||||||||
| 86 | # Loads variables from config file | ||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||
| 88 | ################################################################################ | ||||||||||||||||||||||||||||
| 89 | sub conf | ||||||||||||||||||||||||||||
| 90 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
conf: called CC=15 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 1 | my ($self, $token) = @_; | |||||||||||||||||||||||||||
| 92 | 1 | my ($name, $a, $b) = @{$token->data}; | |||||||||||||||||||||||||||
| 93 | 1 | my (@files, $file, $key, $value, $lastline); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | @files = $self->tokens_execute($a); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | foreach $file (@files) { | |||||||||||||||||||||||||||
| 98 | 1 | ▶ | unless (open CONF, $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($self->warning) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | print STDERR "can't open file '$file': $!\n"; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | next; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | $lastline = ''; | |||||||||||||||||||||||||||
| 106 | 1 | ▶ | while (<CONF>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 15 | ▶ | next if /^\s*$/ or /^\s*#/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^\s*$/ or /^\s*#/
MC/DC100%2/2
/^\s*$/ or /^\s*#/
/^\s*$/
/^\s*#/
Truth table100%3/3
A or B
A= /^\s*$/B= /^\s*#/
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 5 | ▶ | if (s|\\$||) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 2 | chomp; | |||||||||||||||||||||||||||
| 111 | 2 | $lastline =~ s/\s+$/ /; s/^\s+//; | |||||||||||||||||||||||||||
| 112 | 2 | $lastline .= $_; | |||||||||||||||||||||||||||
| 113 | 2 | ▶ | next unless eof CONF; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 3 | ▶ | if (length $lastline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 1 | $lastline =~ s/\s+$/ /; s/^\s+//; | |||||||||||||||||||||||||||
| 118 | 1 | $_ = $lastline . $_; | |||||||||||||||||||||||||||
| 119 | 1 | $lastline = ''; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 3 | s/^\s+//; s/\s+$//; chomp; | |||||||||||||||||||||||||||
| 123 | 3 | ($key, $value) = split(/\s*=\s*/, $_, 2); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 3 | ▶ | unless ($key) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ($self->warning) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | print STDERR "no config variable on line $. of file '$file'\n"; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 0 | next; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 3 | ▶ | if ($self->[PML->PML_V]{$local}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $self->[PML->PML_V]{$key} = $value || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$value || ''
MC/DC0%0/1
$value || ''
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||
| 134 | } elsif ($self->[PML->PML_V]{$prefix}) { | ||||||||||||||||||||||||||||
| 135 | 0 | $self->[PML->PML_V]{$self->[PML->PML_V]{$prefix}}{$key} = $value; | |||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||
| 137 | 3 | $self->[PML->PML_V]{$dprefix}{$key} = $value; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | close CONF; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | return undef; | |||||||||||||||||||||||||||
| 145 | } # <-- End conf --> | ||||||||||||||||||||||||||||
| 146 | ################################################################################ | ||||||||||||||||||||||||||||
| 147 | # END-OF-SCRIPT # | ||||||||||||||||||||||||||||
| 148 | ################################################################################ | ||||||||||||||||||||||||||||
| 149 | =head1 NAME | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | File.pm | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Quick Usage | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | What does it do? | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Long Usage | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Example usage | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | perl(1) | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Peter J Jones | ||||||||||||||||||||||||||||
| 176 | pjones@cpan.org | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | 1; | |||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||