1 # autoconf -- create 'configure' using m4 macros
2 # Copyright (C) 2003, 2006, 2009-2017, 2020-2024 Free Software
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 package Autom4te
::C4che
;
22 Autom4te::C4che - a single m4 run request
30 This Perl module handles the cache of M4 runs used by autom4te.
36 use warnings FATAL
=> 'all';
41 use Autom4te
::Request
;
49 Must be a package global so it can be accessed by code evaluated via
56 =item C<$req = Autom4te::C4che-E<gt>retrieve (%attr)>
58 Find a request with the same path and input.
64 my ($self, %attr) = @_;
70 if join ("\n", @
{$_->path}) ne join ("\n", @
{$attr{path
}});
74 if join ("\n", @
{$_->input}) ne join ("\n", @
{$attr{input
}});
83 =item C<$req = Autom4te::C4che-E<gt>register (%attr)>
85 Create and register a request for these path and input.
90 # register ($SELF, %ATTR)
91 # -----------------------
92 # NEW should not be called directly.
96 my ($self, %attr) = @_;
98 # path and input are the only ID for a request object.
99 my $obj = new Autom4te
::Request
('path' => $attr{path
},
100 'input' => $attr{input
});
103 # Assign an id for cache file.
104 $obj->id ("$#request");
110 =item C<$req = Autom4te::C4che-E<gt>request (%request)>
112 Get (retrieve or create) a request for the path C<$request{path}> and
113 the input C<$request{input}>.
118 # request($SELF, %REQUEST)
119 # ------------------------
122 my ($self, %request) = @_;
125 Autom4te
::C4che
->retrieve (%request)
126 || Autom4te
::C4che
->register (%request);
128 # If there are new traces to produce, then we are not valid.
129 foreach (@
{$request{'macro'}})
131 if (! exists ${$req->macro}{$_})
133 ${$req->macro}{$_} = 1;
138 # It would be great to have $REQ check that it is up to date wrt
139 # its dependencies, but that requires getting traces (to fetch the
140 # included files), which is out of the scope of Request (currently?).
146 =item C<$string = Autom4te::C4che-E<gt>marshall ()>
148 Serialize all the current requests.
159 my $marshall = Data
::Dumper
->new ([\
@request], [qw
(*request
)]);
160 $marshall->Indent(2)->Terse(0);
162 # The Sortkeys method was added in Data::Dumper 2.12_01, so it is
163 # available in 5.8.x and 5.6.2 but not in 5.6.1 or earlier.
164 # Ignore failure of method lookup.
165 eval { $marshall->Sortkeys(1); };
167 return $marshall->Dump . "\n";
171 =item C<Autom4te::C4che-E<gt>save ($file, $version)>
173 Save the cache in the C<$file> file object.
177 # SAVE ($FILE, $VERSION)
178 # ----------------------
181 my ($self, $file, $version) = @_;
183 confess
"cannot save a single request\n"
189 "# This file was generated by Autom4te $version.\n",
190 "# It contains the lists of macros which have been traced.\n",
191 "# It can be safely removed.\n",
197 =item C<Autom4te::C4che-E<gt>good_version ($file, $version)>
199 Succeed if the cache from the C<$file> file object is of the given version.
203 # GOOD_VERSION ($FILE, $VERSION)
204 # ------------------------------
205 sub good_version
($$)
207 my ($self, $file, $version) = @_;
208 my ($line) = $file->getline;
209 return defined ($line) && $line eq "# This file was generated by Autom4te $version.\n";
212 =item C<Autom4te::C4che-E<gt>load ($file)>
214 Load the cache from the C<$file> file object.
222 my ($self, $file) = @_;
223 my $fname = $file->name;
225 confess
"cannot load a single request\n"
228 my $contents = join "", $file->getlines;
232 confess
"cannot eval $fname: $@\n" if $@
;
242 Written by Akim Demaille E<lt>F<akim@freefriends.org>E<gt>.
248 ### Setup "GNU" style for perl-mode and cperl-mode.
250 ## perl-indent-level: 2
251 ## perl-continued-statement-offset: 2
252 ## perl-continued-brace-offset: 0
253 ## perl-brace-offset: 0
254 ## perl-brace-imaginary-offset: 0
255 ## perl-label-offset: -2
256 ## cperl-indent-level: 2
257 ## cperl-brace-offset: 0
258 ## cperl-continued-brace-offset: 0
259 ## cperl-label-offset: -2
260 ## cperl-extra-newline-before-brace: t
261 ## cperl-merge-trailing-else: nil
262 ## cperl-continued-statement-offset: 2