PML/Storable.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 75 CC 5 SCAR 26.1
CC
5
Cov
0%
parse
30.0
new
2.0
BEGIN
2.0
CRAP 13.7
1 #! /usr/bin/perl -w
2 ################################################################################
3 #
4 # Storable.pm (Store a parsed PML Object)
5 #
6 ################################################################################
7 #
8 # Package
9 #
10 ################################################################################
11 package PML::Storable;
12 @ISA = qw( PML );
13 ################################################################################
14 #
15 # Includes
16 #
17 ################################################################################
18 use strict;
19 use Storable;
20 ################################################################################
21 #
22 # Constants
23 #
24 ################################################################################
25 use constant VERSION => '0.01';
26 use constant DATE => 'Mon Jun 5 15:29:33 2000';
27 use constant ID => '$Id: Storable.pm,v 1.3 2000/07/31 17:13:46 pjones Exp $';
28 ################################################################################
29 #
30 # Global Variables and Default Settings
31 #
32 ################################################################################
33 use vars qw($VERSION);
34 $VERSION = VERSION;
35 ################################################################################
36 #
37 # ==== new ==== ################################################################
38 #
39 # Arguments:
40 # 1) Class
41 # 2) Args to PML->new
42 #
43 # Returns:
44 # A PML object reblessed as a PML::Storable Object
45 #
46 # Description:
47 # Creates a new PML object then reblesses it as PML::Storable
48 #
49 ################################################################################
50 sub new
51 {
52 my $class = shift;
53 my $self = new PML @_;
54
55 return bless $self, $class;
56 } # <-- End new -->
57 ################################################################################
58 #
59 # ==== parse ==== ##############################################################
60 #
61 # Arguments:
62 # 1) Filename or ref to an array of lines
63 #
64 # Returns:
65 # None
66 #
67 # Description:
68 # Checks to see if the object is up to date, if not it calls
69 # PML::parse.
70 #
71 ################################################################################
72 sub parse
73 {
74 my ($self, $x) = (shift, @_);
75 my ($stored_filename, $include, $mod);
76
77 # we can't handle arrays or files that don't exist
78 if (ref($x) eq 'ARRAY' or not -e $x) {
79 return $self->SUPER::parse(@_);
80 }
81
82 # replace the dir seperator '/' with a '.'
83 ($stored_filename = $x) =~ s/\//./g;
84
85 # add the obj dir to the front of the filename
86 $stored_filename = $self->[PML->PML_OBJ_DIR] . '/' . $stored_filename;
87 $stored_filename .= '.stored';
88
89 # get the mod time of the obj
90 $mod = -M $stored_filename;
91
92 # see if the obj exists and that it is newer then the src
93 if (not -e $stored_filename or $mod > -M $x) {
94 $self->SUPER::parse(@_);
95 return store $self, $stored_filename;
96 }
97
98 # if we get this far then we need to retrieve the stored obj
99 my $obj = retrieve($stored_filename);
100
101 # make sure we got it
102 unless ($obj) {
103 $self->SUPER::parse(@_);
104 return store $self, $stored_filename;
105 }
106
107 # run through and check the dates on the included files
108 foreach $include (keys %{$obj->[PML->PML_INCLUDES]}) {
109 if (-M $include < $mod) {
110 $self->SUPER::parse(@_);
111 return store $self, $stored_filename;
112 }
113 }
114
115 # if we get here then all include files are up to date
116 # and we should load all the needed modules
117 $self->parse_need($obj->[PML->PML_NEED_LIST]);
118
119 # last we need to is copy over elements from obj to self
120 foreach $x (0 .. 20) {
121 $self->[$x] = $obj->[$x];
122 }
123
124 return 1;
125 } # <-- End parse -->
126 ################################################################################
127 # END-OF-SCRIPT #
128 ################################################################################
129 =head1 NAME
130  
131 Storable.pm
132  
133 =head1 SYNOPSIS
134  
135 Quick Usage
136  
137 =head1 DESCRIPTION
138  
139 What does it do?
140  
141 =head1 OPTIONS
142  
143 Long Usage
144  
145 =head1 EXAMPLES
146  
147 Example usage
148  
149 =head1 SEE ALSO
150  
151 perl(1)
152  
153 =head1 AUTHOR
154  
155 Peter J Jones
156 pjones@cpan.org
157  
158 =cut
159 1;
160