RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / share / autoconf / Autom4te / C4che.pm
bloba5084f5539506f3eb17d067e353d885ccdc2c172
1 # autoconf -- create `configure' using m4 macros
2 # Copyright (C) 2003, 2006, 2009 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;
19 =head1 NAME
21 Autom4te::C4che - a single m4 run request
23 =head1 SYNOPSIS
25 use Autom4te::C4che;
27 =head1 DESCRIPTION
29 This Perl module handles the cache of M4 runs used by autom4te.
31 =cut
33 use Data::Dumper;
34 use Autom4te::Request;
35 use Carp;
36 use strict;
38 =over 4
40 =item @request
42 List of requests.
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.
49 =cut
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.
57 =cut
59 sub retrieve($%)
61 my ($self, %attr) = @_;
63 foreach (@request)
65 # Same path.
66 next
67 if join ("\n", @{$_->path}) ne join ("\n", @{$attr{path}});
69 # Same inputs.
70 next
71 if join ("\n", @{$_->input}) ne join ("\n", @{$attr{input}});
73 # Found it.
74 return $_;
77 return undef;
80 =item C<$req = Autom4te::C4che-E<gt>register (%attr)>
82 Create and register a request for these path and input.
84 =cut
86 # $REQUEST-OBJ
87 # register ($SELF, %ATTR)
88 # -----------------------
89 # NEW should not be called directly.
90 # Private.
91 sub register ($%)
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});
98 push @request, $obj;
100 # Assign an id for cache file.
101 $obj->id ("$#request");
103 return $obj;
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}>.
112 =cut
114 # $REQUEST-OBJ
115 # request($SELF, %REQUEST)
116 # ------------------------
117 sub request ($%)
119 my ($self, %request) = @_;
121 my $req =
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;
131 $req->valid (0);
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?).
139 return $req;
143 =item C<$string = Autom4te::C4che-E<gt>marshall ()>
145 Serialize all the current requests.
147 =cut
150 # marshall($SELF)
151 # ---------------
152 sub marshall ($)
154 my ($caller) = @_;
155 my $res = '';
157 my $marshall = Data::Dumper->new ([\@request], [qw (*request)]);
158 $marshall->Indent(2)->Terse(0);
159 $res = $marshall->Dump . "\n";
161 return $res;
165 =item C<Autom4te::C4che-E<gt>save ($file)>
167 Save the cache in the C<$file> file object.
169 =cut
171 # SAVE ($FILE)
172 # ------------
173 sub save ($$)
175 my ($self, $file) = @_;
177 confess "cannot save a single request\n"
178 if ref ($self);
180 $file->seek (0, 0);
181 $file->truncate (0);
182 print $file
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",
186 "\n",
187 $self->marshall;
191 =item C<Autom4te::C4che-E<gt>load ($file)>
193 Load the cache from the C<$file> file object.
195 =cut
197 # LOAD ($FILE)
198 # ------------
199 sub load ($$)
201 my ($self, $file) = @_;
202 my $fname = $file->name;
204 confess "cannot load a single request\n"
205 if ref ($self);
207 my $contents = join "", $file->getlines;
209 eval $contents;
211 confess "cannot eval $fname: $@\n" if $@;
215 =head1 SEE ALSO
217 L<Autom4te::Request>
219 =head1 HISTORY
221 Written by Akim Demaille E<lt>F<akim@freefriends.org>E<gt>.
223 =cut
225 1; # for require
227 ### Setup "GNU" style for perl-mode and cperl-mode.
228 ## Local Variables:
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
242 ## End: