perl

 view release on metacpan or  search on metacpan

configpm  view on Meta::CPAN

#    =head1 EXAMPLE
#
#    Here's a more sophisticated example of using %Config:
#
#        use Config;
#        use strict;
#
#        my %sig_num;
#        my @sig_name;
#        unless($Config{sig_name} && $Config{sig_num}) {
#            die "No sigs?";
#        } else {
#            my @names = split ' ', $Config{sig_name};
#            @sig_num{@names} = split ' ', $Config{sig_num};
#            foreach (@names) {
#                $sig_name[$sig_num{$_}] ||= $_;
#            }
#        }
#
#        print "signal #17 = $sig_name[17]\n";
#        if ($sig_num{ALRM}) {
#            print "SIGALRM is $sig_num{ALRM}\n";
#        }
#
#    =head1 WARNING
#
#    Because this information is not stored within the perl executable
#    itself it is possible (but unlikely) that the information does not
#    relate to the actual perl binary which is being used to access it.
#
#    The Config module is installed into the architecture and version
#    specific library directory ($Config{installarchlib}) and it checks the
#    perl version number when loaded.
#
#    The values stored in config.sh may be either single-quoted or
#    double-quoted. Double-quoted strings are handy for those cases where you
#    need to include escape sequences in the strings. To avoid runtime variable
#    interpolation, any C<$> and C<@> characters are replaced by C<\$> and
#    C<\@>, respectively. This isn't foolproof, of course, so don't embed C<\$>
#    or C<\@> in double-quoted strings unless you're willing to deal with the
#    consequences. (The slashes will end up escaped and the C<$> or C<@> will
#    trigger variable interpolation)
#
#    =head1 GLOSSARY
#
#    Most C<Config> variables are determined by the C<Configure> script
#    on platforms supported by it (which is most UNIX platforms).  Some
#    platforms have custom-made C<Config> variables, and may thus not have
#    some of the variables described below, or may have extraneous variables
#    specific to that particular port.  See the port specific documentation
#    in such cases.
#
#    =cut
#
ENDOFTAIL

if ($Opts{glossary}) {
  open(GLOS, '<', $Glossary) or die "Can't open $Glossary: $!";
}
my $text = 0;
$/ = '';
my $errors= 0;

my %glossary;

my $fc;
my $item;

sub process {
  if (s/\A(\w*)\s+\(([\w.]+)\):\s*\n(\t?)/=item C<$1>\n\nFrom F<$2>:\n\n/m) {
    $item = $1;
    $fc = substr $item, 0, 1;
  }
  elsif (!$item || !/\A\t/) {
    warn "Expected a Configure variable header",
      ($text ? " or another paragraph of description" : () ),
      ", instead we got:\n$_";
    $errors++;
  }
  s/n't/n\00t/g;		# leave can't, won't etc untouched
  s/^\t\s+(.*)/\n$1/gm;		# Indented lines ===> new paragraph
  s/^(?<!\n\n)\t(.*)/$1/gm;	# Not indented lines ===> text
  s{([\'\"])(?=[^\'\"\s]*[./][^\'\"\s]*\1)([^\'\"\s]+)\1}(F<$2>)g; # '.o'
  s{([\'\"])([^\'\"\s]+)\1}(C<$2>)g; # "date" command
  s{\'([A-Za-z_\- *=/]+)\'}(C<$1>)g; # 'ln -s'
  s{
     (?<! [\w./<\'\"\$] )		# Only standalone file names
     (?! e \. g \. )		# Not e.g.
     (?! \. \. \. )		# Not ...
     (?! \d )			# Not 5.004
     (?! read/ )		# Not read/write
     (?! etc\. )		# Not etc.
     (?! I/O )			# Not I/O
     (
	\$ ?			# Allow leading $
	[\w./]* [./] [\w./]*	# Require . or / inside
     )
     (?<! \. (?= [\s)] ) )	# Do not include trailing dot
     (?! [\w/] )		# Include all of it
   }
   (F<$1>)xg;			# /usr/local
  s/((?<=\s)~\w*)/F<$1>/g;	# ~name
  s/(?<![.<\'\"])\b([A-Z_]{2,})\b(?![\'\"])/C<$1>/g;	# UNISTD
  s/(?<![.<\'\"])\b(?!the\b)(\w+)\s+macro\b/C<$1> macro/g; # FILE_cnt macro
  s/n[\0]t/n't/g;		# undo can't, won't damage
  $glossary{$fc}{$item} .= $_;
}

if ($Opts{glossary}) {
    <GLOS>;				# Skip the "DO NOT EDIT"
    <GLOS>;				# Skip the preamble
  while (<GLOS>) {
    process;
  }
  if ($errors) {
    die "Errors encountered while processing $Glossary. ",
        "Header lines are expected to be of the form:\n",
        "NAME (CLASS):\n",
        "Maybe there is a malformed header?\n",
    ;
  }



( run in 0.672 second using v1.01-cache-2.11-cpan-800906f7e73 )