1 # autoconf -- create `configure' using m4 macros
2 # Copyright (C) 2003, 2006 Free Software Foundation, Inc.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package Autom4te
::C4che
;
21 Autom4te::C4che - a single m4 run request
29 This Perl module handles the cache of M4 runs used by autom4te.
34 use Autom4te
::Request
;
44 We cannot declare it "my" as the loading, performed via "do", would
45 refer to another scope, and @request would not be updated. It used to
46 work with "my" vars, and I do not know whether the current behavior
47 (5.6) is wanted or not.
51 use vars
qw(@request);
53 =item C<$req = Autom4te::C4che-E<gt>retrieve (%attr)>
55 Find a request with the same path and input.
61 my ($self, %attr) = @_;
67 if join ("\n", @{$_->path}) ne join ("\n", @{$attr{path}});
71 if join ("\n", @{$_->input}) ne join ("\n", @{$attr{input}});
80 =item C<$req = Autom4te::C4che-E<gt>register (%attr)>
82 Create and register a request for these path and input.
87 # register ($SELF, %ATTR)
88 # -----------------------
89 # NEW should not be called directly.
93 my ($self, %attr) = @_;
95 # path and input are the only ID for a request object.
96 my $obj = new Autom4te::Request ('path' => $attr{path},
97 'input' => $attr{input});
100 # Assign an id for cache file.
101 $obj->id ("$#request");
107 =item C<$req = Autom4te::C4che-E<gt>request (%request)>
109 Get (retrieve or create) a request for the path C<$request{path}> and
110 the input C<$request{input}>.
115 # request($SELF, %REQUEST)
116 # ------------------------
119 my ($self, %request) = @_;
122 Autom4te::C4che->retrieve (%request)
123 || Autom4te::C4che->register (%request);
125 # If there are new traces to produce, then we are not valid.
126 foreach (@{$request{'macro'}})
128 if (! exists ${$req->macro}{$_})
130 ${$req->macro}{$_} = 1;
135 # It would be great to have $REQ check that it is up to date wrt
136 # its dependencies, but that requires getting traces (to fetch the
137 # included files), which is out of the scope of Request (currently?).
143 =item C<$string = Autom4te::C4che-E<gt>marshall ()>
145 Serialize all the current requests.
157 my $marshall = Data::Dumper->new ([\@request], [qw (*request)]);
158 $marshall->Indent(2)->Terse(0);
159 $res = $marshall->Dump . "\n";
165 =item C<Autom4te::C4che-E<gt>save ($file)>
167 Save the cache in the C<$file> file object.
175 my ($self, $file) = @_;
177 confess "cannot save a single request\n"
183 "# This file was generated.\n",
184 "# It contains the lists of macros which have been traced.\n",
185 "# It can be safely removed.\n",
191 =item C<Autom4te::C4che-E<gt>load ($file)>
193 Load the cache from the C<$file> file object.
201 my ($self, $file) = @_;
202 my $fname = $file->name;
204 confess "cannot load a single request\n"
207 my $contents = join "", $file->getlines;
211 confess "cannot eval $fname: $@\n" if $@;
221 Written by Akim Demaille E<lt>F<akim@freefriends.org>E<gt>.
227 ### Setup "GNU" style for perl-mode and cperl-mode.
229 ## perl-indent-level: 2
230 ## perl-continued-statement-offset: 2
231 ## perl-continued-brace-offset: 0
232 ## perl-brace-offset: 0
233 ## perl-brace-imaginary-offset: 0
234 ## perl-label-offset: -2
235 ## cperl-indent-level: 2
236 ## cperl-brace-offset: 0
237 ## cperl-continued-brace-offset: 0
238 ## cperl-label-offset: -2
239 ## cperl-extra-newline-before-brace: t
240 ## cperl-merge-trailing-else: nil
241 ## cperl-continued-statement-offset: 2