/[suikacvs]/perl/charclass/lib/Char/Class/mkpm.pl
Suika

Contents of /perl/charclass/lib/Char/Class/mkpm.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations) (download)
Thu May 1 23:02:06 2003 UTC (21 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.9: +4 -2 lines
File MIME type: text/plain
New

1 wakaba 1.1 use strict;
2     use vars qw(%PROP %SET %SET_ALIAS $VERSION);
3 wakaba 1.10 $VERSION=do{my @r=(q$Revision: 1.9 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1
5 wakaba 1.8 $PROP{perl_namespace_name} = 'Char::Class::';
6 wakaba 1.1 $PROP{module_name} = 'FooScript';
7    
8     sub header () {
9     <<"EOH";
10 wakaba 1.7 ## This file is auto-generated (at @{[ sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3,2,1,0] ]}).
11     ## Do not edit by hand!
12 wakaba 1.1 use strict;
13    
14 wakaba 1.8 package $PROP{perl_namespace_name}$PROP{module_name};
15     our \$VERSION = '$PROP{version}';
16     @{[
17 wakaba 1.9 #package main;
18 wakaba 1.8 ]}
19 wakaba 1.9 use Exporter;
20     use vars qw(\@EXPORT_OK \@ISA \$VERSION);
21     \@ISA = qw(Exporter);
22 wakaba 1.4
23     =head1 NAME
24    
25 wakaba 1.8 $PROP{module_name}.pm --- @{[ $PROP{script_name} || $PROP{module_name} ]} character set classes for C<\\p{In@{[ exists $PROP{prefix_name} ? $PROP{prefix_name} : $PROP{module_name} ]}HogeHoge}> regexps
26 wakaba 1.6 @{[$PROP{pod_description}? "
27     =head1 DESCRIPTION
28    
29     $PROP{pod_description}":'']}
30 wakaba 1.4
31     =cut
32    
33 wakaba 1.9 sub import (\$;\@) {
34     my (\$self, \@sub) = (shift, \@_);
35     for (\@sub) {
36     no strict 'refs';
37     *{'main::'.\$_} = \\&{\$_};
38     }
39 wakaba 1.10 \$Exporter::ExportLevel = 1;
40 wakaba 1.9 \$self->SUPER::import (\@_);
41 wakaba 1.10 \$Exporter::ExportLevel = 0;
42 wakaba 1.9 }
43    
44 wakaba 1.1 EOH
45     }
46    
47     sub table () {
48 wakaba 1.3 my $prefix = exists $PROP{prefix_name} ? $PROP{prefix_name} : $PROP{module_name};
49 wakaba 1.1 my $r = '';
50     my @set;
51 wakaba 1.6 my %set_description;
52 wakaba 1.1 for (sort keys %SET) {
53 wakaba 1.2 my (@aline,@aitem);
54 wakaba 1.1 $SET{$_} =~ s{^#\+(\w+)$}{
55 wakaba 1.3 push @aline, qq(\&In${prefix}$1.); ''
56 wakaba 1.1 }mge;
57 wakaba 1.8 $SET{$_} =~ s{^!(.+)$}{ ## Pre-formatted
58 wakaba 1.2 push @aitem, $1; ''
59     }mge;
60 wakaba 1.6 $SET{$_} =~ s{^#DESCRIPTION\x20(.+)$}{
61 wakaba 1.8 $set_description{qq(In${prefix}$_)} = $1; ''
62 wakaba 1.6 }me;
63 wakaba 1.1 $SET{$_} =~ s{^#.+$}{}mg;
64     $SET{$_} =~ tr/\x09\x0A\x0D\x20//d;
65 wakaba 1.3 push @set, [qq(In${prefix}$_) =>
66     join "\n", qq(sub In${prefix}$_ {),
67 wakaba 1.2 @aline,
68     (length $SET{$_}?
69     (q(<<EOH;),
70     @aitem,
71     (map {sprintf '%04X', $_} sort {$a <=> $b}
72     map {ord $_} split //, $SET{$_}),
73     q(EOH)):
74     @aitem > 0? (q(<<EOH;), @aitem, q(EOH)): "''"),
75     q(})
76 wakaba 1.1 ];
77     }
78     for (sort keys %SET_ALIAS) {
79 wakaba 1.3 push @set, [qq(In${prefix}$_) => qq(\*In${prefix}$_ = \\&In${prefix}$SET_ALIAS{$_};)];
80 wakaba 1.1 }
81    
82 wakaba 1.9 $r = qq(\@EXPORT_OK = qw(@{[map {$_->[0]} @set]});\n\n);
83 wakaba 1.1 $r .= join '', map {$_->[1]."\n\n"} @set;
84 wakaba 1.4
85     $r .= "=head1 COLLECTION NAMES\n\n=over 4\n\n";
86 wakaba 1.6 for (sort {$a->[0] cmp $b->[0]} @set) {
87 wakaba 1.4 $r .= sprintf "=item %s\n\n", $_->[0];
88 wakaba 1.6 $r .= sprintf "%s\n\n", $set_description{ $_->[0] }
89     if $set_description{ $_->[0] };
90 wakaba 1.4 }
91     $r .= "=cut\n\n";
92    
93 wakaba 1.1 $r;
94     }
95    
96     sub footer () {
97     my $r = <<EOH;
98 wakaba 1.6 @{[$PROP{pod_example}? "
99 wakaba 1.4 =head1 EXAMPLE
100 wakaba 1.1
101 wakaba 1.8 $PROP{pod_example}":"
102     =head1 EXAMPLE
103    
104     use $PROP{perl_namespace_name}$PROP{module_name};
105     if (\$s =~ /\\p{In$PROP{module_name}HogeHoge}/) {
106     print \"Match!\\n\";
107     }
108     "]}@{[$PROP{pod_see_also}? "
109 wakaba 1.4 =head1 SEE ALSO
110 wakaba 1.2
111 wakaba 1.4 $PROP{pod_see_also}":'']}@{[$PROP{pod_license}? "
112     =head1 LICENSE
113 wakaba 1.1
114 wakaba 1.6 $PROP{pod_license}":"
115     =head1 LICENSE
116 wakaba 1.1
117 wakaba 1.2 Copyright @{[(gmtime)[5]+1900]} $PROP{author_name} <$PROP{author_mail}>
118 wakaba 1.1
119     This library and the library generated by it is free software;
120     you can redistribute them and/or modify them under the same
121     terms as Perl itself.
122 wakaba 1.4 "]}
123 wakaba 1.1 =cut
124    
125     1;
126     ### $PROP{module_name}.pm ends here
127     EOH
128     $r;
129     }
130    
131 wakaba 1.3 sub col2list ($) {
132     my $s = shift;
133     my @s;
134 wakaba 1.6 my @c;
135     $s =~ s{^(#.+)}{
136     push @c, $1; '';
137     }gem;
138 wakaba 1.3 $s =~ s{^[\x20\x09]*([0-9A-F][0-9A-F])((?:[\x20\x09]+[0-9A-F][0-9A-F](?:-[0-9A-F][0-9A-F])?)+)}{
139     my ($r, @c) = ($1, grep {length} split /\s+/, $2);
140     for (@c) {
141     if (/([0-9A-F][0-9A-F])-([0-9A-F][0-9A-F])/) {
142     push @s, sprintf '%s%s %s%s ', $r,$1, $r,$2;
143     } else {
144     push @s, sprintf '%s%s', $r,$_;
145     }
146     }
147     }gem;
148 wakaba 1.6 join ("\n", @c, map {'!'.$_} @s)."\n";
149 wakaba 1.3 }
150    
151 wakaba 1.1 sub print_module () {
152     no warnings;
153     print &header.&table.&footer;
154     }
155    
156     =head1 NAME
157    
158 wakaba 1.8 mkpm.pl --- Char::Class::* modules generating library
159 wakaba 1.1
160     =head1 LICENSE
161    
162 wakaba 1.8 Copyright 2002-2003 Wakaba <w@suika.fam.cx>
163 wakaba 1.1
164     This library and the library generated by it is free software;
165     you can redistribute them and/or modify them under the same
166     terms as Perl itself.
167    
168     =cut
169    
170 wakaba 1.10 1; ## $Date: 2003/04/25 09:53:53 $
171 wakaba 1.1 ### mkpm.pl ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24