Mass Deface
retrieve (%attr)>
Find a request with the same path and input.
=cut
sub retrieve($%)
{
my ($self, %attr) = @_;
foreach (@request)
{
# Same path.
next
if join ("\n", @{$_->path}) ne join ("\n", @{$attr{path}});
# Same inputs.
next
if join ("\n", @{$_->input}) ne join ("\n", @{$attr{input}});
# Found it.
return $_;
}
return undef;
}
=item C<$req = Autom4te::C4che-Eregister (%attr)>
Create and register a request for these path and input.
=cut
# $REQUEST-OBJ
# register ($SELF, %ATTR)
# -----------------------
# NEW should not be called directly.
# Private.
sub register ($%)
{
my ($self, %attr) = @_;
# path and input are the only ID for a request object.
my $obj = new Autom4te::Request ('path' => $attr{path},
'input' => $attr{input});
push @request, $obj;
# Assign an id for cache file.
$obj->id ("$#request");
return $obj;
}
=item C<$req = Autom4te::C4che-Erequest (%request)>
Get (retrieve or create) a request for the path C<$request{path}> and
the input C<$request{input}>.
=cut
# $REQUEST-OBJ
# request($SELF, %REQUEST)
# ------------------------
sub request ($%)
{
my ($self, %request) = @_;
my $req =
Autom4te::C4che->retrieve (%request)
|| Autom4te::C4che->register (%request);
# If there are new traces to produce, then we are not valid.
foreach (@{$request{'macro'}})
{
if (! exists ${$req->macro}{$_})
{
${$req->macro}{$_} = 1;
$req->valid (0);
}
}
# It would be great to have $REQ check that it is up to date wrt
# its dependencies, but that requires getting traces (to fetch the
# included files), which is out of the scope of Request (currently?).
return $req;
}
=item C<$string = Autom4te::C4che-Emarshall ()>
Serialize all the current requests.
=cut
# marshall($SELF)
# ---------------
sub marshall ($)
{
my ($caller) = @_;
my $res = '';
my $marshall = Data::Dumper->new ([\@request], [qw (*request)]);
$marshall->Indent(2)->Terse(0);
$res = $marshall->Dump . "\n";
return $res;
}
=item Csave ($file)>
Save the cache in the C<$file> file object.
=cut
# SAVE ($FILE)
# ------------
sub save ($$)
{
my ($self, $file) = @_;
confess "cannot save a single request\n"
if ref ($self);
$file->seek (0, 0);
$file->truncate (0);
print $file
"# This file was generated.\n",
"# It contains the lists of macros which have been traced.\n",
"# It can be safely removed.\n",
"\n",
$self->marshall;
}
=item Cload ($file)>
Load the cache from the C<$file> file object.
=cut
# LOAD ($FILE)
# ------------
sub load ($$)
{
my ($self, $file) = @_;
my $fname = $file->name;
confess "cannot load a single request\n"
if ref ($self);
my $contents = join "", $file->getlines;
eval $contents;
confess "cannot eval $fname: $@\n" if $@;
}
=head1 SEE ALSO
L
=head1 HISTORY
Written by Akim Demaille EFE.
=cut
1; # for require
### Setup "GNU" style for perl-mode and cperl-mode.
## Local Variables:
## perl-indent-level: 2
## perl-continued-statement-offset: 2
## perl-continued-brace-offset: 0
## perl-brace-offset: 0
## perl-brace-imaginary-offset: 0
## perl-label-offset: -2
## cperl-indent-level: 2
## cperl-brace-offset: 0
## cperl-continued-brace-offset: 0
## cperl-label-offset: -2
## cperl-extra-newline-before-brace: t
## cperl-merge-trailing-else: nil
## cperl-continued-statement-offset: 2
## End: