[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: C4che & Request
From: |
Akim Demaille |
Subject: |
FYI: C4che & Request |
Date: |
Fri, 22 Aug 2003 10:11:24 +0200 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) |
Index: ChangeLog
from Akim Demaille <address@hidden>
* lib/Autom4te/Request.pm, lib/Autom4te/C4che.pm: New.
* bin/autom4te.in: Adjust.
Index: bin/autom4te.in
===================================================================
RCS file: /cvsroot/autoconf/autoconf/bin/autom4te.in,v
retrieving revision 1.87
diff -u -u -r1.87 autom4te.in
--- bin/autom4te.in 21 Aug 2003 17:50:11 -0000 1.87
+++ bin/autom4te.in 22 Aug 2003 08:08:18 -0000
@@ -36,212 +36,13 @@
$ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
}
-## --------- ##
-## Request. ##
-## --------- ##
-
-package Request;
-
-use Data::Dumper;
-use Autom4te::FileUtils;
-use Autom4te::General;
-use Autom4te::Struct;
-use Autom4te::XFile;
-use Carp;
-use strict;
-
-# List of requests.
-# We can't declare it `my' as the loading, performed via `do',
-# would refer to another scope, and @request would not be updated.
-# It used to work with `my' vars, and I don't know whether the current
-# behavior (5.6) is wanted or not.
-use vars qw(@request);
-
-struct
- (
- # The key of the cache files.
- 'id' => "\$",
- # True iff %MACRO contains all the macros we want to trace.
- 'valid' => "\$",
- # The include path.
- 'path' => '@',
- # The set of input files.
- 'input' => '@',
- # The set of macros currently traced.
- 'macro' => '%',
- );
-
-
-# $REQUEST-OBJ
-# retrieve ($SELF, %ATTR)
-# -----------------------
-# Find a request with the same path and input.
-# Private.
-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;
-}
-
-
-# $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 = $self->new ('path' => $attr{path},
- 'input' => $attr{input});
- push @request, $obj;
-
- # Assign an id for cache file.
- $obj->id ("$#request");
-
- return $obj;
-}
-
-
-# $REQUEST-OBJ
-# request($SELF, %REQUEST)
-# ------------------------
-# Return a request corresponding to $REQUEST{path} and $REQUEST{input},
-# using a cache value if it exists.
-sub request ($%)
-{
- my ($self, %request) = @_;
-
- my $req = Request->retrieve (%request) || Request->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 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;
-}
-
-# Serialize a request or all the current requests.
-sub marshall
-{
- my ($caller) = @_;
- my $res = '';
-
- if (ref ($caller))
- {
- # CALLER is an object: instance method.
- my $marshall = Data::Dumper->new ([$caller]);
- $marshall->Indent(2)->Terse(0);
- $res = $marshall->Dump . "\n";
- }
- else
- {
- # CALLER is the package: class method.
- my $marshall = Data::Dumper->new (address@hidden, [qw (*request)]);
- $marshall->Indent(2)->Terse(0);
- $res = $marshall->Dump . "\n";
- }
-
- return $res;
-}
-
-
-# includes_p (@MACRO)
-# -------------------
-# Does this request covers all the @MACRO.
-sub includes_p
-{
- my ($self, @macro) = @_;
-
- foreach (@macro)
- {
- return 0
- if ! exists ${$self->macro}{$_};
- }
- return 1;
-}
-
-
-# SAVE ($FILE)
-# ------------
-# Save the cache in the $FILE Autom4te::XFile object.
-sub save
-{
- my ($self, $file) = @_;
-
- croak "$me: cannot save a single request\n"
- if ref ($self);
-
- $file->seek (0, 0);
- $file->truncate (0);
- print $file
- "# This file was created by $me.\n",
- "# It contains the lists of macros which have been traced.\n",
- "# It can be safely removed.\n",
- "\n",
- $self->marshall;
-}
-
-
-# LOAD ($FILE)
-# ------------
-# "eval" the content of the $FILE Autom4te::XFile object.
-sub load
-{
- my ($self, $file) = @_;
- my $fname = $file->name;
-
- croak "$me: cannot load a single request\n"
- if ref ($self);
-
- my $contents = join "", $file->getlines;
-
- eval $contents;
-
- croak "$me: cannot eval $fname: address@hidden" if $@;
-}
-
-
-## ---------- ##
-## Autom4te. ##
-## ---------- ##
-
-package Autom4te;
-
+use Autom4te::C4che;
use Autom4te::ChannelDefs;
use Autom4te::Channels;
use Autom4te::FileUtils;
use Autom4te::General;
-use File::Basename;
use Autom4te::XFile;
+use File::Basename;
use strict;
# Data directory.
@@ -1167,15 +968,15 @@
$icache_file->lock (LOCK_EX);
# Read the cache index if available and older than autom4te itself.
-# If autom4te is younger, then some structures such as Request, might
+# If autom4te is younger, then some structures such as C4che, might
# have changed, which would corrupt its processing.
-Request->load ($icache_file)
+Autom4te::C4che->load ($icache_file)
if -f $icache && mtime ($icache) > mtime ($0);
# Add the new trace requests.
-my $req = Request->request ('input' => address@hidden,
- 'path' => address@hidden,
- 'macro' => [keys %trace, @preselect]);
+my $req = Autom4te::C4che->request ('input' => address@hidden,
+ 'path' => address@hidden,
+ 'macro' => [keys %trace, @preselect]);
# If $REQ's cache files are not up to date, or simply if the user
# discarded them (-f), declare it invalid.
@@ -1219,7 +1020,7 @@
# If we ran up to here, the cache is valid.
$req->valid (1);
-Request->save ($icache_file);
+Autom4te::C4che->save ($icache_file);
exit $exit_code;
Index: lib/Autom4te/C4che.pm
===================================================================
RCS file: lib/Autom4te/C4che.pm
diff -N lib/Autom4te/C4che.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/Autom4te/C4che.pm 22 Aug 2003 08:08:18 -0000
@@ -0,0 +1,245 @@
+# autoconf -- create `configure' using m4 macros
+# Copyright (C) 2003 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+package Autom4te::C4che;
+
+=head1 NAME
+
+Autom4te::C4che - a single m4 run request
+
+=head1 SYNOPSIS
+
+ use Autom4te::C4che;
+
+=head1 DESCRIPTION
+
+This Perl module handles the cache of M4 runs used by autom4te.
+
+=cut
+
+use Data::Dumper;
+use Autom4te::Request;
+use Carp;
+use strict;
+
+=over 4
+
+=item @request
+
+List of requests.
+
+We cannot declare it "my" as the loading, performed via "do", would
+refer to another scope, and @request would not be updated. It used to
+work with "my" vars, and I do not know whether the current behavior
+(5.6) is wanted or not.
+
+=cut
+
+use vars qw(@request);
+
+=item C<$req = Autom4te::C4che-E<gt>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-E<gt>register (%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-E<gt>request (%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 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-E<gt>marshall ()>
+
+Serialize all the current requests.
+
+=cut
+
+
+# marshall($SELF)
+# ---------------
+sub marshall ($)
+{
+ my ($caller) = @_;
+ my $res = '';
+
+ my $marshall = Data::Dumper->new (address@hidden, [qw (*request)]);
+ $marshall->Indent(2)->Terse(0);
+ $res = $marshall->Dump . "\n";
+
+ return $res;
+}
+
+
+=item C<Autom4te::C4che-E<gt>save ($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 C<Autom4te::C4che-E<gt>load ($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: address@hidden" if $@;
+}
+
+
+=head1 SEE ALSO
+
+L<Autom4te::Request>
+
+=head1 HISTORY
+
+Written by Akim Demaille E<lt>F<address@hidden>E<gt>.
+
+=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:
Index: lib/Autom4te/Makefile.am
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/Autom4te/Makefile.am,v
retrieving revision 1.7
diff -u -u -r1.7 Makefile.am
--- lib/Autom4te/Makefile.am 20 Aug 2003 06:51:34 -0000 1.7
+++ lib/Autom4te/Makefile.am 22 Aug 2003 08:08:18 -0000
@@ -2,11 +2,13 @@
perllibdir = $(pkgdatadir)/Autom4te
dist_perllib_DATA = \
+ C4che.pm \
ChannelDefs.pm \
Channels.pm \
Configure_ac.pm \
FileUtils.pm \
General.pm \
+ Request.pm \
Struct.pm \
XFile.pm
Index: lib/Autom4te/Makefile.in
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/Autom4te/Makefile.in,v
retrieving revision 1.31
diff -u -u -r1.31 Makefile.in
--- lib/Autom4te/Makefile.in 20 Aug 2003 06:51:34 -0000 1.31
+++ lib/Autom4te/Makefile.in 22 Aug 2003 08:08:18 -0000
@@ -110,11 +110,13 @@
target_alias = @target_alias@
perllibdir = $(pkgdatadir)/Autom4te
dist_perllib_DATA = \
+ C4che.pm \
ChannelDefs.pm \
Channels.pm \
Configure_ac.pm \
FileUtils.pm \
General.pm \
+ Request.pm \
Struct.pm \
XFile.pm
Index: lib/Autom4te/Request.pm
===================================================================
RCS file: lib/Autom4te/Request.pm
diff -N lib/Autom4te/Request.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/Autom4te/Request.pm 22 Aug 2003 08:08:18 -0000
@@ -0,0 +1,116 @@
+# autoconf -- create `configure' using m4 macros
+# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+package Autom4te::Request;
+
+=head1 NAME
+
+Autom4te::Request - a single m4 run request
+
+=head1 SYNOPSIS
+
+ use Autom4te::Request;
+
+=head1 DESCRIPTION
+
+This perl module provides various general purpose support functions
+used in several executables of the Autoconf and Automake packages.
+
+=cut
+
+use strict;
+use Autom4te::Struct;
+use Carp;
+use Data::Dumper;
+
+struct
+ (
+ # The key of the cache files.
+ 'id' => "\$",
+ # True iff %MACRO contains all the macros we want to trace.
+ 'valid' => "\$",
+ # The include path.
+ 'path' => '@',
+ # The set of input files.
+ 'input' => '@',
+ # The set of macros currently traced.
+ 'macro' => '%',
+ );
+
+
+# Serialize a request or all the current requests.
+sub marshall($)
+{
+ my ($caller) = @_;
+ my $res = '';
+
+ # CALLER is an object: instance method.
+ my $marshall = Data::Dumper->new ([$caller]);
+ $marshall->Indent(2)->Terse(0);
+ $res = $marshall->Dump . "\n";
+
+ return $res;
+}
+
+
+# includes_p ($SELF, @MACRO)
+# --------------------------
+# Does this request covers all the @MACRO.
+sub includes_p
+{
+ my ($self, @macro) = @_;
+
+ foreach (@macro)
+ {
+ return 0
+ if ! exists ${$self->macro}{$_};
+ }
+ return 1;
+}
+
+
+=head1 SEE ALSO
+
+L<Autom4te::C4che>
+
+=head1 HISTORY
+
+Written by Akim Demaille E<lt>F<address@hidden>E<gt>.
+
+=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:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: C4che & Request,
Akim Demaille <=