@@ -56,7 +56,7 @@ use PPI::Document ();
56
56
57
57
our $VERSION = ' 1.282' ;
58
58
59
- use constant VMS => !! ( $^O eq ' VMS' );
59
+ use constant VMS => !!( $^O eq ' VMS' );
60
60
61
61
sub import {
62
62
my $class = ref $_ [0] ? ref shift : shift ;
@@ -66,17 +66,13 @@ sub import {
66
66
my $cache = $class -> new(@_ );
67
67
68
68
# Make PPI::Document use it
69
- unless ( PPI::Document-> set_cache( $cache ) ) {
69
+ unless ( PPI::Document-> set_cache($cache ) ) {
70
70
Carp::croak(" Failed to set cache in PPI::Document" );
71
71
}
72
72
73
73
1;
74
74
}
75
75
76
-
77
-
78
-
79
-
80
76
# ####################################################################
81
77
# Constructor and Accessors
82
78
@@ -115,21 +111,21 @@ sub new {
115
111
116
112
# Path should exist and be usable
117
113
my $path = $params {path }
118
- or Carp::croak(" Cannot create PPI::Cache, no path provided" );
114
+ or Carp::croak(" Cannot create PPI::Cache, no path provided" );
119
115
unless ( -d $path ) {
120
116
Carp::croak(" Cannot create PPI::Cache, path does not exist" );
121
117
}
122
118
unless ( -r $path and -x $path ) {
123
119
Carp::croak(" Cannot create PPI::Cache, no read permissions for path" );
124
120
}
125
- if ( ! $params {readonly } and ! -w $path ) {
121
+ if ( !$params {readonly } and !-w $path ) {
126
122
Carp::croak(" Cannot create PPI::Cache, no write permissions for path" );
127
123
}
128
124
129
125
# Create the basic object
130
126
my $self = bless {
131
127
path => $path ,
132
- readonly => !! $params {readonly },
128
+ readonly => !!$params {readonly },
133
129
}, $class ;
134
130
135
131
$self ;
@@ -157,10 +153,6 @@ to the cache.
157
153
158
154
sub readonly { $_ [0]-> {readonly } }
159
155
160
-
161
-
162
-
163
-
164
156
# ####################################################################
165
157
# PPI::Cache Methods
166
158
@@ -174,9 +166,10 @@ cache and retrieves it if so.
174
166
=cut
175
167
176
168
sub get_document {
177
- my $self = ref $_ [0]
178
- ? shift
179
- : Carp::croak(' PPI::Cache::get_document called as static method' );
169
+ my $self =
170
+ ref $_ [0]
171
+ ? shift
172
+ : Carp::croak(' PPI::Cache::get_document called as static method' );
180
173
my $md5hex = $self -> _md5hex(shift ) or return undef ;
181
174
$self -> _load($md5hex );
182
175
}
@@ -196,7 +189,7 @@ FIXME (make this return either one or the other, not both)
196
189
197
190
sub store_document {
198
191
my $self = shift ;
199
- my $Document = _INSTANCE(shift , ' PPI::Document' ) or return undef ;
192
+ my $Document = _INSTANCE( shift , ' PPI::Document' ) or return undef ;
200
193
201
194
# Shortcut if we are readonly
202
195
return 1 if $self -> readonly;
@@ -208,43 +201,42 @@ sub store_document {
208
201
$self -> _store( $md5hex , $Document );
209
202
}
210
203
211
-
212
-
213
-
214
-
215
204
# ####################################################################
216
205
# Support Methods
217
206
218
207
# Store an arbitrary PPI::Document object (using Storable) to a particular
219
208
# path within the cache filesystem.
220
209
sub _store {
221
- my ($self , $md5hex , $object ) = @_ ;
222
- my ($dir , $file ) = $self -> _paths($md5hex );
210
+ my ( $self , $md5hex , $object ) = @_ ;
211
+ my ( $dir , $file ) = $self -> _paths($md5hex );
223
212
224
213
# Save the file
225
214
File::Path::mkpath( $dir , 0, 0755 ) unless -d $dir ;
226
- if ( VMS ) {
215
+ if (VMS) {
227
216
Storable::lock_nstore( $object , $file );
228
- } else {
217
+ }
218
+ else {
229
219
Storable::nstore( $object , $file );
230
220
}
231
221
}
232
222
233
223
# Load an arbitrary object (using Storable) from a particular
234
224
# path within the cache filesystem.
235
225
sub _load {
236
- my ($self , $md5hex ) = @_ ;
237
- my (undef , $file ) = $self -> _paths($md5hex );
226
+ my ( $self , $md5hex ) = @_ ;
227
+ my ( undef , $file ) = $self -> _paths($md5hex );
238
228
239
229
# Load the file
240
230
return ' ' unless -f $file ;
241
- my $object = VMS
242
- ? Storable::retrieve( $file )
243
- : Storable::lock_retrieve( $file );
231
+ my $object =
232
+ VMS
233
+ ? Storable::retrieve($file )
234
+ : Storable::lock_retrieve($file );
244
235
245
236
# Security check
246
- unless ( _INSTANCE($object , ' PPI::Document' ) ) {
247
- Carp::croak(" Security Violation: Object in '$file ' is not a PPI::Document" );
237
+ unless ( _INSTANCE( $object , ' PPI::Document' ) ) {
238
+ Carp::croak(
239
+ " Security Violation: Object in '$file ' is not a PPI::Document" );
248
240
}
249
241
250
242
$object ;
@@ -254,20 +246,25 @@ sub _load {
254
246
sub _paths {
255
247
my $self = shift ;
256
248
my $md5hex = lc shift ;
257
- my $dir = File::Spec-> catdir( $self -> path, substr ($md5hex , 0, 1), substr ($md5hex , 0, 2) );
258
- my $file = File::Spec-> catfile( $dir , $md5hex . ' .ppi' );
259
- return ($dir , $file );
249
+ my $dir = File::Spec-> catdir(
250
+ $self -> path,
251
+ substr ( $md5hex , 0, 1 ),
252
+ substr ( $md5hex , 0, 2 )
253
+ );
254
+ my $file = File::Spec-> catfile( $dir , $md5hex . ' .ppi' );
255
+ return ( $dir , $file );
260
256
}
261
257
262
258
# Check a md5hex param
263
259
sub _md5hex {
264
260
my $either = shift ;
265
- my $it = _SCALAR($_ [0])
266
- ? PPI::Util::md5hex(${$_ [0]})
267
- : $_ [0];
268
- return (defined $it and ! ref $it and $it =~ / ^[[:xdigit:]]{32}\z /s )
269
- ? lc $it
270
- : undef ;
261
+ my $it =
262
+ _SCALAR( $_ [0] )
263
+ ? PPI::Util::md5hex( ${ $_ [0] } )
264
+ : $_ [0];
265
+ return ( defined $it and !ref $it and $it =~ / ^[[:xdigit:]]{32}\z /s )
266
+ ? lc $it
267
+ : undef ;
271
268
}
272
269
273
270
1;
0 commit comments