Front page | perl.perl5.porters |
Postings from January 2002
Re: [ID 20020126.007] enhancement to h2xs
Thread Previous
From:
Robert Spier
Date:
January 29, 2002 09:49
Subject:
Re: [ID 20020126.007] enhancement to h2xs
Message ID:
15446.57497.507119.826287@rls.cx
A few suggestions/comments:
1. IMHO- I don't like the addition of a new environment variable.
It seems this could be easier served by a command line option
to point to a defaults file.
2. Your .h2xsrc file parser is very specific. What if I want
something to be more than one line long?
3. You make a lot of UNIXy assumptions (which isn't bad.)
(Attached to this, there seems to be a lot of checks to do
something pretty simple.)
4. Your $^O check won't get windows (win32) right.
I think the concept is good and useful, although I don't know how
often you run h2xs - I've never found it a problem to tweak these
things by hand after the fact.
How about a command line option for a file (containing perl source
code, so you don't have to worry about parsing it.)?
--snip--
$AUTHOR="My Name";
$LICENSE=<<EOF;
This is the license.
Etc.
EOF
my $year = (localtime())[5];
$COPYRIGHT = "Copyright $year $AUTHOR";
--snip--
This could then be evaluated with a do or eval, and wouldn't have any
platform specific stuff in it.
-R
David Martin writes:
>Greetings,
>
>I am using Perl 5.7.2 development version downloaded a week ago.
>
>This is more a functionality increase than a bug, patch file attached,
>particularly:
>
>added a PERLH2XS environment variable to point to either a file or directory
>to contain a preferences file for the AUTHOR, EMAIL, COPYRIGHT, and LICENSE
>information, limited to this list of keywords. Default filenames for the
>preferences file are .h2xsrc (unixes for example) or h2xs.ini for
>dos/windows/vms. directories are checked in order of PERLH2XS, HOME, or
>LOGDIR environment variable directories -- swiped this part pretty well
>straight out of perl5db.pl (Randal's suggestion). Updated the POD
>documentation also. Additionally changed the ||= operator for $author to the
>ternary operator, so now it does find my name out by looking it up on the
>system if there is no dot file.
>
>I do not have access to very many types of operating systems, but it appears
>to work correctly on my linux laptop. I did not do anything especially
>scary, so it should generally work okay.
>
>Thanks,
>
>David Martin
>penguipotamous@yahoo.com341c341,356
>< No environment variables are used.
>---
>> PERLH2XS set to the directory and filename or just directory.
>> Here is a sample of how the file should look:
>>
>> AUTHOR Justanother Perlhacker
>> EMAIL justanexample@perl.com
>> LICENSE Same as PERL itself.
>> COPYRIGHT Perl Foundation
>>
>> h2xs will attempt to find .h2xsrc or h2xsrc.ini depending on the
>> operating system custom in order by directory name plus path
>> or just directory defined by PERLH2XS, then by either of HOME or
>> LOGDIR directories.
>>
>> AUTHOR defaults to best-guess if AUTHOR is omitted.
>>
>> COPYRIGHT defaults to AUTHOR if COPYRIGHT is omitted.
>465a481,527
>> # get a list of potential keys out of a preferences file
>> sub get_h2xsrc {
>> my $rc = shift;
>>
>> my $rcfile = '.h2xsrc'; # default to something plausible
>> if ( $^O =~ m/dos|window|vms/i ) {
>> $rcfile="h2xs.ini";
>> }
>>
>> # pieces of this are from perl5db.pl - adapted since I plan to parse
>> # the file as text rather than executing it directly. (DTM)
>> # look first by path and name, then by default name in a directory
>> if (defined $ENV{'PERLH2XS'} && -f "$ENV{'PERLH2XS'}") {
>> $rcfile = "$ENV{'PERLH2XS'}";
>> }
>> elsif (defined $ENV{'PERLH2XS'} && -f "$ENV{'PERLH2XS'}/$rcfile") {
>> $rcfile = "$ENV{'PERLH2XS'}/$rcfile";
>> }
>> # choose a home directory to read dotfile from
>> elsif (defined $ENV{'HOME'} && -f "$ENV{'HOME'}/$rcfile") {
>> $rcfile = "$ENV{'HOME'}/$rcfile";
>> }
>> elsif (defined $ENV{'LOGDIR'} && -f "$ENV{'LOGDIR'}/$rcfile") {
>> $rcfile = "$ENV{'LOGDIR'}/$rcfile";
>> }
>> else{ return; }
>>
>> if ( open( RC, "<$rcfile" ) ) {
>> while(<RC>) {
>> next if /^#/;
>> chomp;
>> s/^\s+//g;
>> my @line = split( /[ |=]/, $_ );
>> my $key = shift @line;
>> $key = uc $key;
>> for my $param ( keys %{$rc} ) {
>> if( $key eq $param ) {
>> $$rc{$key} = join " ", @line;
>> }
>> }
>> }
>> close RC;
>> }
>> }
>>
>>
>>
>673d734
><
>967c1028,1033
>< my ($email,$author);
>---
>> my ($email,$author, $license, $copyright ) = (
>> 'a.u.thor@a.galaxy.far.far.away',
>> 'A. U. Thor',
>> "This library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.",
>> 'A. U. Thor'
>> );
>978,979c1044,1050
>< $author ||= "A. U. Thor";
>< $email ||= 'a.u.thor@a.galaxy.far.far.away';
>---
>>
>> my %prefs = ( AUTHOR => 0, EMAIL => 0, LICENSE => 0, COPYRIGHT => 0 );
>> get_h2xsrc( \%prefs );
>> $author = $prefs{'AUTHOR'} ? $prefs{'AUTHOR'} : $author;
>> $email = $prefs{'EMAIL'} ? $prefs{'EMAIL'} : $email;
>> $license = $prefs{'LICENSE'} ? $prefs{'LICENSE'} : $license;
>> $copyright = $prefs{'COPYRIGHT'} ? $prefs{'COPYRIGHT'} : $author;
>1075c1146
>< #=head1 COPYRIGHT AND LICENSE
>---
>> #=head1 COPYRIGHT
>1077c1148
>< #Copyright ${\(1900 + (localtime) [5])} by $author
>---
>> #Copyright ${\(1900 + (localtime) [5])} by $copyright
>1079,1080c1150,1152
>< #This library is free software; you can redistribute it and/or modify
>< #it under the same terms as Perl itself.
>---
>> #=head1 LICENSE
>> #
>> #$license
>1646c1718,1720
>< COPYRIGHT AND LICENCE
>---
>> COPYRIGHT
>>
>> Put the correct copyright and license information here.
>1648c1722
>< Put the correct copyright and licence information here.
>---
>> Copyright (C) $thisyear $copyright
>1650c1724
>< Copyright (C) $thisyear $author
>---
>> LICENSE
>1652,1653c1726
>< This library is free software; you can redistribute it and/or modify
>< it under the same terms as Perl itself.
>---
>> $license
--
Thread Previous