/[suikacvs]/messaging/manakai/lib/Message/Util/AutoLoad/Config.pm
Suika

Contents of /messaging/manakai/lib/Message/Util/AutoLoad/Config.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sat Nov 4 12:25:19 2006 UTC (19 years, 10 months ago) by wakaba
Branch: MAIN
CVS Tags: manakai-200612
Changes since 1.1: +43 -5 lines
++ manakai/bin/ChangeLog	4 Nov 2006 11:58:05 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* daf.pl: The |--debug| option no longer set
	obsoleted |$Message::DOM::DOMFeature::DEBUG| option.

++ manakai/lib/Message/Markup/ChangeLog	4 Nov 2006 12:14:20 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Atom.dis (AtomImplementation): It no
        longer inherits the |ManakaiDOMImplementation|; it
        is now expected to be implemented by |DOMImplementation|
        objects.
	(AtomDocument, AtomFeedDocument, AtomEntryDocument): It no
        longer inherits the |ManakaiDOMDocument|; it
        is now expected to be implemented by |Document|
        objects.

	* SuikaWikiConfig21.dis (SWCFGImplementation): It no
        longer inherits the |DOMImplementation|; it
        is now expected to be implemented by |DOMImplementation|
        objects.

++ manakai/lib/Message/Util/ChangeLog	4 Nov 2006 12:18:18 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DIS.dis (ManakaiDISImplementation): It no longer
	inherits |ManakaiDISImplementationValue|,
	|ManakaiDISImplementationPerl|, and |ManakaiSWCFGImplementation|
	interfaces.  The class is now expected to be implemented
	by |DOMImplementation| objects.

	* PerlCode.dis (addImplementedFeature, addImplementedElementType):
	New methods.
	(PCHasFeature, PCElementType): New interfaces.
	(PCDocument): It no longer inherits the |ManakaiDOMDocument|; it
        is now expected to be implemented by |Document|
        objects.
	(PCImplementation): It no longer inherits the |ManakaiDOMImplementation|;
	it is now expected to be implemented by |DOMImplementation|
	objects.

++ manakai/lib/Message/Util/DIS/ChangeLog	4 Nov 2006 12:24:32 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DNLite.dis (DISImplementationDNLite): It no
	longer inherits the |ManakaiDISImplementation|; it
        is now expected to be implemented by |DOMImplementation| objects.

	* DPG.dis (DPGDocument): It no longer inherits
	the |ManakaiDOMDocument| class; it is now expected to be
	implemented by all |Document| objects.

	* Perl.dis (DISImplementationPerl): It is now
	expected to be implemented by all |DOMImplementation| objects.
	(plCodeFragment): Support for the |p:require|
	property is added.  It no longer output |ClassInfo|
	for classes for specific element types; instead,
	it invoke |add_implemented_element_type| method.

	* Test.dis (DTImplementation): It no longer
	inherits the |MinimumImplementation| interface;
	instead, it is expected to be implemented
	by all |DOMImplementation| objects.

	* Value.dis (DISImplementationValue): It is now
	expected to be implemented by all |DOMImplementation| objects.

++ manakai/lib/Message/Util/AutoLoad/ChangeLog	4 Nov 2006 12:19:43 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Config.pm (register_all, save): Support for |feature|
	and |element_type| is added.

	* Registry-initial.pm: Updated.

	* .cvsignore: New file.


	* Registry-initial.pm: New module.
++ manakai/lib/Message/DOM/ChangeLog	4 Nov 2006 12:12:45 -0000
	explicitly inherits |urigen:ManakaiURIImplementation| (and
	the |f:ManakaiMinimumImplementation| class inherited
	by it).  The |f:Minimum| feature is ever implemented
	for compatibility (but is expected to be removed).
	Internal methods such as |___report_error| are copied from
	obsolete |f:MinimumImplementation| class.  DOM3
	methods |hasFeature| and |getFeature| are also
	moved from that class, but they now support no
	foreign classes.

	* DOMFeature.dis (ManakaiImplementationSource): It
	now |p:require|s |Message::Util::AutoLoad::Registry|.
	The class no longer support classes
	other than |ManakaiDOMImplementation|.  Note
	that the |ImplementationRegistry| object does continue
	to support foreign classes via foreign classes
	implementing |ImplementationSource|
	or |DOMImplementationSource| interface.
	(MinimumImplementation): Removed.

	* DOMLS.dis (ManakaiDOMImplementationLS): It no
	longer inherit the |ManakaiDOMImplementation|; it
	is now expected to be implemented by |DOMImplementation|
	objects.

	* DOMMain.dis (null): Removed.

	* Document.dis (___create_node_ref): It no
	longer support foreign classes other
	than |Message::DOM::Document::ManakaiDOMDocument|.
	Note that document format specific DOM
	interfaces, if supported, should be
	all instances of the |Document| interface
	in the implementation, as defined
	in the Web Applications 1.0 specification (where
	the |HTMLDocument| interface must be implemented
	by all |Document| objects, even if the |Document|
	contains no HTML element).

	* GenericLS.dis (GLSImplementation): It no
        longer inherit the |MinimumImplementation|; it
        is now expected to be implemented by |DOMImplementation|
        objects.
	(createGLSParser, createGLSSerializer): Load
	module implementing parser or serializer
	if necessary.

	* Traversal.dis (ManakaiDOMDocumentTraversal): It no
	longer inherits the |ManakaiDOMDocument|; it
	is now expected to be implemented by |Document|
	objects.

	* XDP.dis (XDPDocument): It no longer
	inherits the |Document|; it is now expected
	to be implemented by all |Document| objects.

	* XDoctype.dis (ManakaiDOMDocumentXDoctype): It no
        longer inherits the |ManakaiDOMDocument|; it
        is now expected to be implemented by |Document|
        objects.

2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DOMCore.dis (ManakaiDOMImplementation): No longer
++ manakai/lib/Message/URI/ChangeLog	4 Nov 2006 12:14:59 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Generic.dis (URIImplementation): It no
	longer inherits the |MinimumImplementation|; it
	is now expected to be implemented by |DOMImplementation|
	objects.

++ manakai/lib/Message/Charset/ChangeLog	4 Nov 2006 11:56:24 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Encode.dis (MCEncodeImplementation): It no
	longer inherit the |MinimumImplementation|; it
	is now expected to be implemented by |DOMImplementation|
	objects.

++ manakai/lib/manakai/ChangeLog	4 Nov 2006 12:25:03 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DISPerl.dis (p:require, p:use): New properties.

1 wakaba 1.1 =head1 NAME
2    
3     Message::Util::AutoLoad::Config - manakai's Autoload Configurator
4    
5     =head1 DESCRIPTION
6    
7     The C<Message::Util::AutoLoad::Config> module provides
8     a way to register a Perl module to the autoload registry.
9    
10     =cut
11    
12     use strict;
13     package Message::Util::AutoLoad::Config;
14 wakaba 1.2 our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
15 wakaba 1.1
16     use Data::Dumper;
17     our $Modified;
18    
19     =head1 SYNOPSIS
20    
21     use Message::Util::AutoLoad::Config;
22     my $config = new Message::Util::AutoLoad::Config;
23    
24     $config->register_method ($class_name, $method_name, $module_name);
25    
26     =head1 METHODS
27    
28     =over 4
29    
30     =item $config = Message::Util::AutoLoad::Config->new;
31    
32     Creates a new instance of the autoload configurator.
33    
34     =cut
35    
36     sub new ($) {
37     my $class = shift;
38     require Message::Util::AutoLoad::Registry;
39     return bless {}, $class;
40     } # new
41    
42     =item $config->register_method ($class_name, $method_name, $module_name, $method_class_name, $prototype);
43    
44     Associates a pair of class and method into a module so
45     that invocation to the method on an object of that class
46     will autoload the module.
47    
48     If the pair is already associated with any module,
49     then that association is removed and the new association
50     takes effect.
51    
52     =over 4
53    
54     =item $class_name
55    
56     The fully-qualified package name of the class.
57    
58     =item $method_name
59    
60     The name of the method. It does not include the package
61     name.
62    
63     =item $module_name
64    
65     The fully-qualified package name of the module.
66    
67     =item $prototype
68    
69     The subroutine prototype (not including parentheses).
70     It may be C<undef>, which stands for no prototype.
71    
72     =item $method_class_name
73    
74     The fully-qualified package name of the class
75     to which the method belongs.
76    
77     =back
78    
79     =cut
80    
81     sub register_method ($$$$$) {
82     my ($self, $class, $method, $module, $class2, $proto) = @_;
83     $Message::Util::AutoLoad::Registry::Method->{$class}->{$method} = {
84     module => $module,
85     class => $class2,
86     prototype => $proto,
87     };
88     $Modified = 1;
89     } # register_method
90    
91     =item $config->register_all ($list);
92    
93     Registers a set of autoload definitions
94     returned by C<< I<PCDocument>->get_autoload_definition_list >>.
95    
96     =over 4
97    
98     =item $list
99    
100     A set of autoload definitions.
101    
102     =back
103    
104     =cut
105    
106     sub register_all ($$) {
107     my ($self, $list) = @_;
108 wakaba 1.2
109 wakaba 1.1 for my $class (keys %{$list->{method} or {}}) {
110     for my $method (keys %{$list->{method}->{$class}}) {
111     $Message::Util::AutoLoad::Registry::Method->{$class}->{$method}
112     = $list->{method}->{$class}->{$method};
113     $Modified = 1;
114     }
115     }
116 wakaba 1.2
117     for my $fname (keys %{$list->{feature} or {}}) {
118     $Message::Util::AutoLoad::Registry::Feature->{$fname}->{$_}
119     = $list->{feature}->{$fname}->{$_}
120     for keys %{$list->{feature}->{$fname}};
121     $Modified = 1;
122     }
123    
124     for my $nsuri (keys %{$list->{element_type} or {}}) {
125     $Message::Util::AutoLoad::Registry::ElementType->{$nsuri}->{$_}
126     = $list->{element_type}->{$nsuri}->{$_}
127     for keys %{$list->{element_type}->{$nsuri}};
128     $Modified = 1;
129     }
130 wakaba 1.1 } # register_all
131    
132     =item $config->save;
133    
134     Writes the current configuration for autoload
135     to the C<Message::Util::AutoLoad::Registry> file
136     (if the autoload configuration is modified through
137     C<Message::Util::AutoLoad::Config> module).
138    
139     =cut
140    
141     sub save ($) {
142     return unless $Modified;
143     my @time = gmtime time;
144     my $r = <<EOH;
145     ## This file is automatically generated at @{[
146     sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ',
147     $time[5] + 1900, $time[4] + 1, $time[3], $time[2], $time[1], $time[0]]}.
148     ## Don't edit by hand!
149    
150     package Message::Util::AutoLoad::Registry;
151     use strict;
152    
153     EOH
154    
155 wakaba 1.2 local $Data::Dumper::Sortkeys = 1;
156    
157 wakaba 1.1 ## Method-to-module mapping
158     my $method = Dumper ($Message::Util::AutoLoad::Registry::Method);
159     $method =~ s/\$VAR1/our \$Method/;
160     $r .= $method;
161    
162 wakaba 1.2 ## Feature-to-module mapping
163     my $feature = Dumper ($Message::Util::AutoLoad::Registry::Feature);
164     $feature =~ s/\$VAR1/our \$Feature/;
165     $r .= $feature;
166    
167     ## Element-type-to-module mapping
168     my $et = Dumper ($Message::Util::AutoLoad::Registry::ElementType);
169     $et =~ s/\$VAR1/our \$ElementType/;
170     $r .= $et;
171    
172 wakaba 1.1 ## Method prototype declarations for |can| method
173     my $clean = sub {
174     join '::', map {
175     s/[^A-Za-z0-9_]/_/g;
176     s/^[0-9]/_/;
177     $_;
178     } grep {length} split /::/, shift;
179     };
180     my $class_methods = {};
181     my $class_revisas = {};
182     for my $pack (keys %$Message::Util::AutoLoad::Registry::Method) {
183     next unless keys %{$Message::Util::AutoLoad::Registry::Method->{$pack}};
184     my $pack_name = $clean->($pack);
185     for my $method
186     (keys %{$Message::Util::AutoLoad::Registry::Method->{$pack}}) {
187     my $m = $Message::Util::AutoLoad::Registry::Method->{$pack}->{$method};
188     my $method_name = $clean->($method);
189     my $class_name = $clean->($m->{class});
190     $class_methods->{$class_name}->{$method_name}
191     = defined $m->{prototype} ? " ($m->{prototype})" : '';
192 wakaba 1.2 $class_revisas->{$class_name}->{$pack_name} = $clean->($m->{module});
193 wakaba 1.1 }
194     }
195     for my $class_name (keys %$class_methods) {
196     $r .= "package $class_name;\n";
197     for my $method_name (keys %{$class_methods->{$class_name}}) {
198     $r .= "sub $method_name$class_methods->{$class_name}->{$method_name};\n";
199     }
200     }
201     for my $class_name (keys %$class_revisas) {
202     my $al_pack_name;
203     for my $pack_name (keys %{$class_revisas->{$class_name}}) {
204     $r .= "push \@${pack_name}::ISA, '$class_name'
205     unless $pack_name->isa ('$class_name');\n";
206 wakaba 1.2 $al_pack_name ||= $class_revisas->{$class_name}->{$pack_name};
207 wakaba 1.1 }
208 wakaba 1.2 $r .= <<EOH;
209     sub ${class_name}::AUTOLOAD {
210     require $al_pack_name;
211     no strict 'refs';
212     if ($class_name->can (\$${class_name}::AUTOLOAD)) {
213     goto &{\$${class_name}::AUTOLOAD};
214     } else {
215     require Carp;
216     Carp::croak (qq<Can't locate method "\$${class_name}::AUTOLOAD">);
217     }
218     }
219     EOH
220 wakaba 1.1 }
221    
222     $r .= <<EOH;
223    
224     1;
225    
226     \__END__
227    
228     \=head1 NAME
229    
230     Message::Util::AutoLoad::Registry - manakai's Autoload Registry
231    
232     \=head1 DESCRIPTION
233    
234     This file is used as the registry for the autoload
235     mechanism used in manakai.
236    
237     EOH
238    
239     my $file_name = $main::INC{'Message/Util/AutoLoad/Registry.pm'};
240     open my $file, '>', $file_name or die "$0: $file_name: $!";
241     print $file $r;
242     close $file;
243     $Modified = 0;
244     } # save
245    
246     =back
247    
248     =head1 LICENSE
249    
250     Copyright 2006 Wakaba <[email protected]>
251    
252     This program is free software; you can redistribute it and/or
253     modify it under the same terms as Perl itself.
254    
255     =cut
256    
257 wakaba 1.2 1; # $Date: 2006/11/03 17:53:34 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24