perl-unicode

Re: Encode 1.76 Released

2002-09-01 02:30:04
On Sat, 31 Aug 2002 23:34:09 +0900, Dan Kogai 
<dankogai(_at_)dan(_dot_)co(_dot_)jp> said:

  > On Friday, August 30, 2002, at 08:48 , Andreas J. Koenig wrote:
Hi Dan,

today I revisited enc2xs and found three things missing:

  > Okay....

- enc2xs doesn't write a MANIFEST file: this would be handy as the
innocent user doesn't know which files need to be included in a
distribution

  > I reckon your suggestion is to 'let enc2xs generate any missing files
  > that are enough to CPANize the encoding'.  is there any other file
  > missing?  MANIFEST autogeneration is trivial but I still prefer 'make
  > manifest'....

Apparently I'm missing something. 'make manifest' is only good for the
expert, because you need to know which lines you have to delete from
MANIFEST after running 'make manifest'. That's not obvious. If you
know a trivial way to write a correct MANIFEST file, I'd be grateful
if you could add it. Maybe then some of my documentation changes are
not needed.

- no -h or --help option

  > I'm not sure enc2xs be used frequently enough to call for the need for
  > -h but there is no reason not to add one.  Maybe detailed info on -M
  > and very, very brief description on -o and such that are not supposed
  > to be invoked by human (even I don't do that except for debugging).

Done. It's probably briefer that you like.

- no -v or --version option

  > This should return the version of Encode.pm as well as enc2xs itself.

Done.

I'd volunteer to add all that if you'd be inclined to accept (and
proofread) it. Please let me know what you think.

  > I am glad you help me out (well, your trust level is so high that you
  > can do all the work and all I do is put your new version to my
  > repository -- and claim the credit (c) ams).

That would be nice, eh? But I'm sorry, I had to put an "XXX" in the
patch, because I'm not sure how it's supposed to work.

  > But I am not so happy if enc2xs becomes behemoth like h2xs.  Man, I
  > thought I had soothed all the feeping creaturism before the release of
  > 5.8.0....

Please see if the patch below makes it a behemoth. It does just the
following:

Add Usage().
Add Version().
Add -h and -v.
Die on an insufficient commandline.
Removed @ARGV from the arguments to call the to make_configlocal_pm().
Document what find_e2x does in a comment.
Speed up find_e2x considerably.
Tweak documentation.

I believe that both find_e2x and the way encode.h are found in the
Makefile.PL are flawed. They rely on timestamps for directories.
Timestamps of directories are influenced by many things, that is
action at a distance. I suppose both should be replaced by something
like

   require Encode;
   $incdir = File::Basename::dirname($INC{"Encode.pm"});

I left these untouched.

I also believe that the search algorithm for enc2xs itself is flawed.
It should be replaced by $^X plus some fallback mechanism for systems
where $^X doesn't work. Note also the hardcoded "enc2xs5.7.3".

I left that untouched too. Didn't want to do too many things in a
single patch.

-- 
andreas

--- Encode-1.76/bin/enc2xs      Sun Aug 25 17:10:25 2002
+++ enc2xs      Sun Sep  1 11:08:12 2002
@@ -5,9 +5,13 @@
     # In case we need it in future...
     require Config; import Config;
 }
+
+sub Usage ();
+sub Version ();
+
 use strict;
 use Getopt::Std;
-my @orig_ARGV = @ARGV;
+my @orig_ARGV = @ARGV or die Usage;
 our $VERSION  = do { my @r = (q$Revision: 1.30 $ =~ /\d+/g); sprintf 
"%d."."%02d" x $#r, @r };
 
 # These may get re-ordered.
@@ -131,10 +135,18 @@
 # -o <output> to specify the output file name (else it's the first arg)
 # -f <inlist> to give a file with a list of input files (else use the args)
 # -n <name> to name the encoding (else use the basename of the input file.
-getopts('CM:SQqOo:f:n:',\%opt);
+getopts('CM:OQSf:hn:oq:v',\%opt);
 
-$opt{M} and make_makefile_pl($opt{M}, @ARGV);
-$opt{C} and make_configlocal_pm($opt{C}, @ARGV);
+print Usage and exit if $opt{h};
+print Version and exit if $opt{v};
+if ( $opt{M} ) {
+  unless (@ARGV) {
+    warn "Error: no table files given on commandline\n";
+    die Usage;
+  }
+  make_makefile_pl($opt{M}, @ARGV);
+}
+$opt{C} and make_configlocal_pm($opt{C});
 
 # This really should go first, else the die here causes empty (non-erroneous)
 # output files to be written.
@@ -856,11 +868,13 @@
     $_Now
 );
 
+# finds *.e2x templates (files with the .e2x extension) in @INC,
+# returns the youngest directory that contains any of them
 sub find_e2x{
     eval { require File::Find };
     my (@inc, %e2x_dir);
     for my $inc (@INC){
-       push @inc, $inc unless $inc eq '.'; #skip current dir
+       push @inc, "$inc/Encode" unless $inc eq '.'; #skip current dir
     }
     File::Find::find(
             sub {
@@ -980,6 +994,33 @@
        print $out $_;
     }
 }
+
+sub Usage () {
+  qq{Usage: $0 [OPTIONS] mapfiles...
+
+     -M modname      Namespace below Encode::
+                     this option is required to generate Makefile.PL,
+                     README, Changes, I<modname>.pm and a test file
+     -C              add your encoding to Encode's demand-loading list
+     -h              This help message
+     -v              print version number and exit
+
+Example:
+
+    enc2xs -M My Encode/*ucm
+
+Many more options for Encode hackers are only documented in the source.
+};
+}
+
+sub Version (){
+  eval { require Encode };
+  my $v = $@ ? "not available" : "version $Encode::VERSION";
+  qq{enc2xs version $VERSION
+Encode $v
+};
+}
+
 __END__
 
 =head1 NAME
@@ -994,7 +1035,7 @@
 
 =head1 DESCRIPTION
 
-F<enc2xs> builds a Perl extension for use by Encode from either
+F<enc2xs> builds a template for a Perl extension for use by Encode from either
 Unicode Character Mapping files (.ucm) or Tcl Encoding Files (.enc).
 Besides being used internally during the build process of the Encode
 module, you can use F<enc2xs> to add your own encoding to perl.
@@ -1025,20 +1066,28 @@
   $ enc2xs -M My my.ucm
   generating Makefile.PL
   generating My.pm
+  generating t/My.t
   generating README
   generating Changes
 
 Now take a look at your current directory.  It should look like this.
 
   $ ls -F
-  Makefile.PL   My.pm         my.ucm        t/
+  Changes  Makefile.PL  My.pm  README  my.ucm  t/
 
 The following files were created.
 
+  Changes     - rudimentary Changes file
   Makefile.PL - MakeMaker script
   My.pm       - Encode submodule
+  README      - rudimentary README file
   t/My.t      - test file
 
+Note, no XS and auxiliary files have been generated yet. This will be
+done during C<perl Makefile.PL> and C<make>. The former will generate
+C<My.xs> and C<My_t.fnm> and the latter will generate C<My_t.exh> and
+C<My_t.h> and then build the whole encoding. See below.
+
 =over 4
 
 =item 1.1.
@@ -1111,6 +1160,13 @@
 
 to update Encode::ConfigLocal, a module that controls local settings.
 After that, "use Encode;" is enough to load your encodings on demand.
+
+=item 8.
+
+If you want to distribute the resulting module, you will most probably
+want to add a MANIFEST file to the collection of files you have now.
+C<make manifest> will do that for you, but it will include all files
+you have now, so that you need to delete not needed files. XXX
 
 =back
 


END_OF_PATCH

<Prev in Thread] Current Thread [Next in Thread>