home *** CD-ROM | disk | FTP | other *** search
- package Config;
- use Exporter ();
- @ISA = (Exporter);
- @EXPORT = qw(%Config);
- @EXPORT_OK = qw(myconfig config_sh config_vars);
-
- $] == 5.00201
- or die "Perl lib version (5.00201) doesn't match executable version ($])\n";
-
- # This file was created by configpm when Perl was built. Any changes
- # made to this file will be lost the next time perl is built.
-
- ##
- ## Manually created configuration file for Macintii
- ## Configuration time: 07Apr96
- ## Configured by: Matthias Neeracher <neeri@iis.ee.ethz.ch>
- ## Target system: Apple Macintosh
- #
-
- my $config_sh = <<'!END!';
- extensions='DB_File DynaLoader Fcntl GDBM_File NDBM_File POSIX SDBM_File Socket'
- static_ext='DynaLoader'
- osname='MacOS'
- osvers='7.5'
- archlibexp=''
- archname=''
- installarchlib=''
- cc='C'
- ccflags=''
- cppflags=''
- dlsrc=''
- libpth=''
- libs=''
- prefix=''
- installprivlib=''
- privlibexp=''
- sig_name=''
- so=''
- sharpbang=''
- shsharp=''
- startsh=''
- Author='neeri'
- CONFIG='true'
- Date=''
- Header=''
- Id=''
- Locker=''
- Log=''
- Mcc='C'
- PATCHLEVEL='0'
- RCSfile=''
- Revision=''
- Source=''
- State=''
- afs=''
- alignbytes=''
- aphostname=''
- archlib=''
- awk='gawk'
- bash=''
- bin=''
- binexp=''
- bison='bison'
- byacc='byacc'
- byteorder='4321'
- c=''
- castflags='0'
- cat='Catenate'
- cccdlflags=''
- ccdlflags=''
- cf_by=''
- cf_time=''
- chgrp=''
- chmod=''
- chown=''
- clocktype='clock_t'
- compress='Stuffit'
- contains=''
- cp='Duplicate'
- cpio=''
- cpp='C -e'
- cpp_stuff=''
- cpplast=''
- cppminus=''
- cpprun=''
- cppstdin=''
- cryptlib=''
- csh=''
- d_Gconvert='undef'
- d_access='undef'
- d_alarm='undef'
- d_archlib='undef'
- d_attrib='undef'
- d_bcmp='define'
- d_bcopy='define'
- d_bsdpgrp='undef'
- d_bzero='define'
- d_casti32='32'
- d_castneg='define'
- d_charsprf='undef'
- d_charvspr='undef'
- d_chown='undef'
- d_chroot='undef'
- d_chsize='undef'
- d_closedir='define'
- d_const='define'
- d_crypt='undef'
- d_csh='undef'
- d_cuserid='undef'
- d_dbl_dig='define'
- d_difftime='define'
- d_dirnamlen='define'
- d_dlerror='undef'
- d_dlopen='undef'
- d_dlsymun='undef'
- d_dosuid='undef'
- d_drem='undef'
- d_dup2='2'
- d_eunice='undef'
- d_fchmod='define'
- d_fchown='undef'
- d_fcntl='define'
- d_fd_macros='define'
- d_fd_set='define'
- d_fds_bits='define'
- d_fgetpos='define'
- d_flexfnam='define'
- d_flock='undef'
- d_fmod='define'
- d_fork='undef'
- d_fpathconf='undef'
- d_fsetpos='define'
- d_getgrps='undef'
- d_gethent='undef'
- d_gethname='define'
- d_getlogin='undef'
- d_getpgrp2='undef'
- d_getpgrp='undef'
- d_getppid='undef'
- d_getprior='undef'
- d_group='undef'
- d_htonl='define'
- d_index='undef'
- d_isascii='define'
- d_killpg='undef'
- d_link='undef'
- d_linuxstd='undef'
- d_locconv='undef'
- d_lockf='undef'
- d_lstat='define'
- d_mblen='undef'
- d_mbstowcs='define'
- d_mbtowc='define'
- d_memcmp='define'
- d_memcpy='define'
- d_memmove='define'
- d_memset='define'
- d_mkdir='define'
- d_mkfifo='undef'
- d_mktime='define'
- d_msg='undef'
- d_msgctl='undef'
- d_msgget='undef'
- d_msgrcv='undef'
- d_msgsnd='undef'
- d_mymalloc='undef'
- d_nice='undef'
- d_oldsock='undef'
- d_open3='3'
- d_passwd='undef'
- d_pathconf='undef'
- d_pause='undef'
- d_phostname='undef'
- d_pipe='undef'
- d_portable='undef'
- d_pwage='undef'
- d_pwchange='undef'
- d_pwclass='undef'
- d_pwcomment='undef'
- d_pwexpire='undef'
- d_pwquota='undef'
- d_readdir='define'
- d_readlink='define'
- d_rename='define'
- d_rewinddir='define'
- d_rmdir='define'
- d_safebcpy='define'
- d_safemcpy='undef'
- d_seekdir='define'
- d_select='define'
- d_sem='undef'
- d_semctl='undef'
- d_semget='undef'
- d_semop='undef'
- d_setegid='undef'
- d_seteuid='undef'
- d_setlinebuf='undef'
- d_setlocale='define'
- d_setpgid='undef'
- d_setpgrp2='2'
- d_setpgrp='undef'
- d_setprior='undef'
- d_setregid='undef'
- d_setresgid='undef'
- d_setresuid='undef'
- d_setreuid='undef'
- d_setrgid='undef'
- d_setruid='undef'
- d_setsid='undef'
- d_shm='undef'
- d_shmat='undef'
- d_shmatprototype='undef'
- d_shmctl='undef'
- d_shmdt='undef'
- d_shmget='undef'
- d_socket='define'
- d_sockpair='undef'
- d_statblks='undef'
- d_stdstdio='define'
- d_strchr='define'
- d_strcoll='undef'
- d_strctcpy='undef'
- d_strerrm='undef'
- d_strerror='define'
- d_strxfrm='define'
- d_suidsafe='undef'
- d_symlink='define'
- d_syscall='undef'
- d_sysconf='undef'
- d_sysernlst='undef'
- d_syserrlst='undef'
- d_system='undef'
- d_tcgetpgrp='undef'
- d_tcsetpgrp='undef'
- d_telldir='define'
- d_time='define'
- d_times='define'
- d_truncate='undef'
- d_tzname='undef'
- d_umask='define'
- d_uname='undef'
- d_vfork='undef'
- d_void_closedir='undef'
- d_voidsig='undef'
- d_voidtty='undef'
- d_volatile='define'
- d_vprintf='define'
- d_wait4='undef'
- d_waitpid='undef'
- d_wcstombs='define'
- d_wctomb='define'
- d_xenix='undef'
- date='Date'
- defvoidused=''
- direntrytype='dirent'
- dlext=''
- echo='Echo'
- egrep='egrep'
- emacs='$emacs'
- eunicefix=':'
- expr='Evaluate'
- find=''
- flex='flex'
- fpostype='fpos_t'
- gcc='gcc'
- gccversion=''
- gidtype=''
- glibpth=''
- grep='grep'
- groupcat=''
- groupstype=''
- h_fcntl='true'
- h_sysfile='false'
- hint=''
- hostcat=''
- huge=''
- i_bsdioctl=''
- i_db='define'
- i_dbm='define'
- i_dirent='define'
- i_dld=''
- i_dlfcn=''
- i_fcntl='define'
- i_float='define'
- i_gdbm='undef'
- i_grp='undef'
- i_limits='define'
- i_malloc='undef'
- i_math='define'
- i_memory='define'
- i_ndbm='define'
- i_neterrno='undef'
- i_niin='undef'
- i_pwd='undef'
- i_sgtty=''
- i_stdarg='define'
- i_stddef='define'
- i_stdlib='define'
- i_string='define'
- i_sysdir='undef'
- i_sysfile='undef'
- i_sysfilio=''
- i_sysin='define'
- i_sysioctl='define'
- i_sysndir=''
- i_sysparam=''
- i_sysselct=''
- i_syssockio=''
- i_systime='define'
- i_systimek=''
- i_systimes=''
- i_termio=''
- i_termios=''
- i_time='define'
- i_unistd='define'
- i_utime=''
- i_varargs=''
- i_varhdr='stdarg.h'
- i_vfork=''
- incpath=''
- inews=''
- installbin=''
- installmansrc=''
- installscript=''
- intsize='32'
- known_extensions='DB_File DynaLoader Fcntl GDBM_File NDBM_File ODBM_File POSIX SDBM_File Socket'
- ksh=''
- large=''
- lddlflags=''
- ldflags=''
- less=''
- libc=''
- libswanted=''
- line='line'
- lint=''
- lkflags=''
- ln=''
- lns=''
- lp=''
- lpr='Print'
- ls='Directory'
- lseektype=''
- mail=''
- mailx=''
- make='BuildProgram'
- mallocobj=''
- mallocsrc=''
- malloctype=''
- manext=''
- mansrc=''
- mansrcexp=''
- medium=''
- mips=''
- mips_type=''
- mkdir='NewFolder'
- models=''
- modetype=''
- more=''
- mv='Move'
- mydomain=''
- myhostname=''
- myuname=''
- n=''
- nm_opt=''
- nroff=''
- optimize=''
- orderlib=''
- package=''
- passcat=''
- perl='Perl'
- pg=''
- phostname=''
- plibpth=''
- pmake=''
- pr=''
- privlib=''
- prototype=''
- randbits=''
- ranlib=''
- rm='Delete'
- rmail=''
- runnm=''
- scriptdir=''
- scriptdirexp=''
- sed='sed'
- selecttype=''
- sendmail=''
- sh=''
- shar=''
- shmattype=''
- signal_t='signal_t'
- sizetype=''
- sleep=''
- smail=''
- small=''
- sockethdr=''
- socketlib=''
- sort='Sort'
- spackage=''
- spitshell=''
- split=''
- ssizetype=''
- startperl='Perl -Sx "{0}" {"Parameters"}; Exit {Status}\n#!perl'
- stdchar=''
- strings='define'
- submit=''
- sysman=''
- tail=''
- tar=''
- tbl=''
- test=''
- timeincl='time.h'
- timetype='time_t'
- touch='SetFile -m .'
- tr=''
- troff=''
- uidtype=''
- uname=''
- uniq=''
- usedl=''
- usemymalloc=''
- usenm=''
- useposix='true'
- usevfork=''
- usrinc=''
- uuname=''
- vi=''
- voidflags=''
- xlibpth=''
- yacc=''
- yaccflags=''
- zcat=''
- !END!
-
- my $summary = <<'!END!';
- Summary of my $package ($baserev patchlevel $PATCHLEVEL subversion $SUBVERSION) configuration:
- Platform:
- osname=$osname, osver=$osvers, archname=$archname
- uname='$myuname'
- hint=$hint, useposix=$useposix, d_sigaction=$d_sigaction
- Compiler:
- cc='$cc', optimize='$optimize', gccversion=$gccversion
- cppflags='$cppflags'
- ccflags ='$ccflags'
- stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
- voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
- intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
- Linker and Libraries:
- ld='$ld', ldflags ='$ldflags'
- libpth=$libpth
- libs=$libs
- libc=$libc, so=$so
- Dynamic Linking:
- dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun, ccdlflags='$ccdlflags'
- cccdlflags='$cccdlflags', lddlflags='$lddlflags'
-
- !END!
- my $summary_expanded = 0;
-
- sub myconfig {
- return $summary if $summary_expanded;
- $summary =~ s/\$(\w+)/$Config{$1}/ge;
- $summary_expanded = 1;
- $summary;
- }
-
- tie %Config, Config;
- sub TIEHASH { bless {} }
- sub FETCH {
- # check for cached value (which maybe undef so we use exists not defined)
- return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
-
- my($value); # search for the item in the big $config_sh string
- return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
-
- $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
- $value =~ s/\\n/\n/g; # macintosh
- $_[0]->{$_[1]} = $value; # cache it
- return $value;
- }
-
- my $prevpos = 0;
-
- sub FIRSTKEY {
- $prevpos = 0;
- my($key) = $config_sh =~ m/^(.*?)=/;
- $key;
- }
-
- sub NEXTKEY {
- my $pos = index($config_sh, "\n", $prevpos) + 1;
- my $len = index($config_sh, "=", $pos) - $pos;
- $prevpos = $pos;
- $len > 0 ? substr($config_sh, $pos, $len) : undef;
- }
-
- sub EXISTS {
- exists($_[0]->{$_[1]}) or $config_sh =~ m/^$_[1]=/m;
- }
-
- sub STORE { die "\%Config::Config is read-only\n" }
- sub DELETE { &STORE }
- sub CLEAR { &STORE }
-
-
- sub config_sh {
- $config_sh
- }
- sub config_vars {
- foreach(@_){
- my $v=(exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
- $v='undef' unless defined $v;
- print "$_='$v';\n";
- }
- }
-
- 1;
- __END__
-
- =head1 NAME
-
- Config - access Perl configuration information
-
- =head1 SYNOPSIS
-
- use Config;
- if ($Config{'cc'} =~ /gcc/) {
- print "built by gcc\n";
- }
-
- use Config qw(myconfig config_sh config_vars);
-
- print myconfig();
-
- print config_sh();
-
- config_vars(qw(osname archname));
-
-
- =head1 DESCRIPTION
-
- The Config module contains all the information that was available to
- the C<Configure> program at Perl build time (over 900 values).
-
- Shell variables from the F<config.sh> file (written by Configure) are
- stored in the readonly-variable C<%Config>, indexed by their names.
-
- Values stored in config.sh as 'undef' are returned as undefined
- values. The perl C<exists> function can be used to check is a
- named variable exists.
-
- =over 4
-
- =item myconfig()
-
- Returns a textual summary of the major perl configuration values.
- See also C<-V> in L<perlrun/Switches>.
-
- =item config_sh()
-
- Returns the entire perl configuration information in the form of the
- original config.sh shell variable assignment script.
-
- =item config_vars(@names)
-
- Prints to STDOUT the values of the named configuration variable. Each is
- printed on a separate line in the form:
-
- name='value';
-
- Names which are unknown are output as C<name='UNKNOWN';>.
- See also C<-V:name> in L<perlrun/Switches>.
-
- =back
-
- =head1 EXAMPLE
-
- Here's a more sophisticated example of using %Config:
-
- use Config;
-
- defined $Config{sig_name} || die "No sigs?";
- foreach $name (split(' ', $Config{sig_name})) {
- $signo{$name} = $i;
- $signame[$i] = $name;
- $i++;
- }
-
- print "signal #17 = $signame[17]\n";
- if ($signo{ALRM}) {
- print "SIGALRM is $signo{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.
-
- =head1 NOTE
-
- This module contains a good example of how to use tie to implement a
- cache and an example of how to make a tied variable readonly to those
- outside of it.
-
- =cut
-
-