diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2010-09-24 15:07:13 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2010-09-24 15:07:13 +0000 |
commit | 6a200b5cffd015c92893c51dd9f24ea861480b4d (patch) | |
tree | 2a683165d8d7277646395e2458d754213d8ff7dc /gnu/usr.bin/perl/lib | |
parent | b514202b410a11d5f4a03be7f2e67ca623ff1ab7 (diff) |
merge in perl 5.12.2 plus local changes
Diffstat (limited to 'gnu/usr.bin/perl/lib')
39 files changed, 1194 insertions, 312 deletions
diff --git a/gnu/usr.bin/perl/lib/Carp.pm b/gnu/usr.bin/perl/lib/Carp.pm index c06f949cc7e..b2948ea7664 100644 --- a/gnu/usr.bin/perl/lib/Carp.pm +++ b/gnu/usr.bin/perl/lib/Carp.pm @@ -1,9 +1,6 @@ package Carp; -our $VERSION = '1.11'; -# this file is an utra-lightweight stub. The first time a function is -# called, Carp::Heavy is loaded, and the real short/longmessmess_jmp -# subs are installed +our $VERSION = '1.17'; our $MaxEvalLen = 0; our $Verbose = 0; @@ -17,6 +14,21 @@ our @EXPORT = qw(confess croak carp); our @EXPORT_OK = qw(cluck verbose longmess shortmess); our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode +# The members of %Internal are packages that are internal to perl. +# Carp will not report errors from within these packages if it +# can. The members of %CarpInternal are internal to Perl's warning +# system. Carp will not report errors from within these packages +# either, and will not report calls *to* these packages for carp and +# croak. They replace $CarpLevel, which is deprecated. The +# $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval +# text and function arguments should be formatted when printed. + +# disable these by default, so they can live w/o require Carp +$CarpInternal{Carp}++; +$CarpInternal{warnings}++; +$Internal{Exporter}++; +$Internal{'Exporter::Heavy'}++; + # if the caller specifies verbose usage ("perl -MCarp=verbose script.pl") # then the following method will be called by the Exporter which knows # to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word @@ -24,29 +36,279 @@ our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ } -# fixed hooks for stashes to point to -sub longmess { goto &longmess_jmp } -sub shortmess { goto &shortmess_jmp } -# these two are replaced when Carp::Heavy is loaded -sub longmess_jmp { - local($@, $!); - eval { require Carp::Heavy }; - return $@ if $@; - goto &longmess_real; -} -sub shortmess_jmp { - local($@, $!); - eval { require Carp::Heavy }; - return $@ if $@; - goto &shortmess_real; -} +sub longmess { + # Icky backwards compatibility wrapper. :-( + # + # The story is that the original implementation hard-coded the + # number of call levels to go back, so calls to longmess were off + # by one. Other code began calling longmess and expecting this + # behaviour, so the replacement has to emulate that behaviour. + my $call_pack = defined &{"CORE::GLOBAL::caller"} ? &{"CORE::GLOBAL::caller"}() : caller(); + if ($Internal{$call_pack} or $CarpInternal{$call_pack}) { + return longmess_heavy(@_); + } + else { + local $CarpLevel = $CarpLevel + 1; + return longmess_heavy(@_); + } +}; + +sub shortmess { + # Icky backwards compatibility wrapper. :-( + local @CARP_NOT = defined &{"CORE::GLOBAL::caller"} ? &{"CORE::GLOBAL::caller"}() : caller(); + shortmess_heavy(@_); +}; sub croak { die shortmess @_ } sub confess { die longmess @_ } sub carp { warn shortmess @_ } sub cluck { warn longmess @_ } +sub caller_info { + my $i = shift(@_) + 1; + my %call_info; + { + package DB; + @args = \$i; # A sentinal, which no-one else has the address of + @call_info{ + qw(pack file line sub has_args wantarray evaltext is_require) + } = defined &{"CORE::GLOBAL::caller"} ? &{"CORE::GLOBAL::caller"}($i) : caller($i); + } + + unless (defined $call_info{pack}) { + return (); + } + + my $sub_name = Carp::get_subname(\%call_info); + if ($call_info{has_args}) { + my @args; + if (@DB::args == 1 && ref $DB::args[0] eq ref \$i && $DB::args[0] == \$i) { + @DB::args = (); # Don't let anyone see the address of $i + @args = "** Incomplete caller override detected; \@DB::args were not set **"; + } else { + @args = map {Carp::format_arg($_)} @DB::args; + } + if ($MaxArgNums and @args > $MaxArgNums) { # More than we want to show? + $#args = $MaxArgNums; + push @args, '...'; + } + # Push the args onto the subroutine + $sub_name .= '(' . join (', ', @args) . ')'; + } + $call_info{sub_name} = $sub_name; + return wantarray() ? %call_info : \%call_info; +} + +# Transform an argument to a function into a string. +sub format_arg { + my $arg = shift; + if (ref($arg)) { + $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg"; + } + if (defined($arg)) { + $arg =~ s/'/\\'/g; + $arg = str_len_trim($arg, $MaxArgLen); + + # Quote it? + $arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/; + } else { + $arg = 'undef'; + } + + # The following handling of "control chars" is direct from + # the original code - it is broken on Unicode though. + # Suggestions? + utf8::is_utf8($arg) + or $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg; + return $arg; +} + +# Takes an inheritance cache and a package and returns +# an anon hash of known inheritances and anon array of +# inheritances which consequences have not been figured +# for. +sub get_status { + my $cache = shift; + my $pkg = shift; + $cache->{$pkg} ||= [{$pkg => $pkg}, [trusts_directly($pkg)]]; + return @{$cache->{$pkg}}; +} + +# Takes the info from caller() and figures out the name of +# the sub/require/eval +sub get_subname { + my $info = shift; + if (defined($info->{evaltext})) { + my $eval = $info->{evaltext}; + if ($info->{is_require}) { + return "require $eval"; + } + else { + $eval =~ s/([\\\'])/\\$1/g; + return "eval '" . str_len_trim($eval, $MaxEvalLen) . "'"; + } + } + + return ($info->{sub} eq '(eval)') ? 'eval {...}' : $info->{sub}; +} + +# Figures out what call (from the point of view of the caller) +# the long error backtrace should start at. +sub long_error_loc { + my $i; + my $lvl = $CarpLevel; + { + ++$i; + my $pkg = defined &{"CORE::GLOBAL::caller"} ? &{"CORE::GLOBAL::caller"}($i) : caller($i); + unless(defined($pkg)) { + # This *shouldn't* happen. + if (%Internal) { + local %Internal; + $i = long_error_loc(); + last; + } + else { + # OK, now I am irritated. + return 2; + } + } + redo if $CarpInternal{$pkg}; + redo unless 0 > --$lvl; + redo if $Internal{$pkg}; + } + return $i - 1; +} + + +sub longmess_heavy { + return @_ if ref($_[0]); # don't break references as exceptions + my $i = long_error_loc(); + return ret_backtrace($i, @_); +} + +# Returns a full stack backtrace starting from where it is +# told. +sub ret_backtrace { + my ($i, @error) = @_; + my $mess; + my $err = join '', @error; + $i++; + + my $tid_msg = ''; + if (defined &threads::tid) { + my $tid = threads->tid; + $tid_msg = " thread $tid" if $tid; + } + + my %i = caller_info($i); + $mess = "$err at $i{file} line $i{line}$tid_msg\n"; + + while (my %i = caller_info(++$i)) { + $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; + } + + return $mess; +} + +sub ret_summary { + my ($i, @error) = @_; + my $err = join '', @error; + $i++; + + my $tid_msg = ''; + if (defined &threads::tid) { + my $tid = threads->tid; + $tid_msg = " thread $tid" if $tid; + } + + my %i = caller_info($i); + return "$err at $i{file} line $i{line}$tid_msg\n"; +} + + +sub short_error_loc { + # You have to create your (hash)ref out here, rather than defaulting it + # inside trusts *on a lexical*, as you want it to persist across calls. + # (You can default it on $_[2], but that gets messy) + my $cache = {}; + my $i = 1; + my $lvl = $CarpLevel; + { + + my $called = defined &{"CORE::GLOBAL::caller"} ? &{"CORE::GLOBAL::caller"}($i) : caller($i); + $i++; + my $caller = defined &{"CORE::GLOBAL::caller"} ? &{"CORE::GLOBAL::caller"}($i) : caller($i); + + return 0 unless defined($caller); # What happened? + redo if $Internal{$caller}; + redo if $CarpInternal{$caller}; + redo if $CarpInternal{$called}; + redo if trusts($called, $caller, $cache); + redo if trusts($caller, $called, $cache); + redo unless 0 > --$lvl; + } + return $i - 1; +} + + +sub shortmess_heavy { + return longmess_heavy(@_) if $Verbose; + return @_ if ref($_[0]); # don't break references as exceptions + my $i = short_error_loc(); + if ($i) { + ret_summary($i, @_); + } + else { + longmess_heavy(@_); + } +} + +# If a string is too long, trims it with ... +sub str_len_trim { + my $str = shift; + my $max = shift || 0; + if (2 < $max and $max < length($str)) { + substr($str, $max - 3) = '...'; + } + return $str; +} + +# Takes two packages and an optional cache. Says whether the +# first inherits from the second. +# +# Recursive versions of this have to work to avoid certain +# possible endless loops, and when following long chains of +# inheritance are less efficient. +sub trusts { + my $child = shift; + my $parent = shift; + my $cache = shift; + my ($known, $partial) = get_status($cache, $child); + # Figure out consequences until we have an answer + while (@$partial and not exists $known->{$parent}) { + my $anc = shift @$partial; + next if exists $known->{$anc}; + $known->{$anc}++; + my ($anc_knows, $anc_partial) = get_status($cache, $anc); + my @found = keys %$anc_knows; + @$known{@found} = (); + push @$partial, @$anc_partial; + } + return exists $known->{$parent}; +} + +# Takes a package and gives a list of those trusted directly +sub trusts_directly { + my $class = shift; + no strict 'refs'; + no warnings 'once'; + return @{"$class\::CARP_NOT"} + ? @{"$class\::CARP_NOT"} + : @{"$class\::ISA"}; +} + 1; + __END__ =head1 NAME @@ -175,12 +437,51 @@ Defaults to C<8>. =head2 $Carp::Verbose -This variable makes C<carp> and C<cluck> generate stack backtraces +This variable makes C<carp> and C<croak> generate stack backtraces just like C<cluck> and C<confess>. This is how C<use Carp 'verbose'> is implemented internally. Defaults to C<0>. +=head2 @CARP_NOT + +This variable, I<in your package>, says which packages are I<not> to be +considered as the location of an error. The C<carp()> and C<cluck()> +functions will skip over callers when reporting where an error occurred. + +NB: This variable must be in the package's symbol table, thus: + + # These work + our @CARP_NOT; # file scope + use vars qw(@CARP_NOT); # package scope + @My::Package::CARP_NOT = ... ; # explicit package variable + + # These don't work + sub xyz { ... @CARP_NOT = ... } # w/o declarations above + my @CARP_NOT; # even at top-level + +Example of use: + + package My::Carping::Package; + use Carp; + our @CARP_NOT; + sub bar { .... or _error('Wrong input') } + sub _error { + # temporary control of where'ness, __PACKAGE__ is implicit + local @CARP_NOT = qw(My::Friendly::Caller); + carp(@_) + } + +This would make C<Carp> report the error as coming from a caller not +in C<My::Carping::Package>, nor from C<My::Friendly::Caller>. + +Also read the L</DESCRIPTION> section above, about how C<Carp> decides +where the error is reported from. + +Use C<@CARP_NOT>, instead of C<$Carp::CarpLevel>. + +Overrides C<Carp>'s use of C<@ISA>. + =head2 %Carp::Internal This says what packages are internal to Perl. C<Carp> will never diff --git a/gnu/usr.bin/perl/lib/Env.pm b/gnu/usr.bin/perl/lib/Env.pm index eb9187fc901..deac5fc4b92 100644 --- a/gnu/usr.bin/perl/lib/Env.pm +++ b/gnu/usr.bin/perl/lib/Env.pm @@ -1,6 +1,6 @@ package Env; -our $VERSION = '1.00'; +our $VERSION = '1.01'; =head1 NAME @@ -132,8 +132,7 @@ sub TIEARRAY { sub FETCHSIZE { my ($self) = @_; - my @temp = split($sep, $ENV{$$self}); - return scalar(@temp); + return 1 + scalar(() = $ENV{$$self} =~ /\Q$sep\E/g); } sub STORESIZE { @@ -161,6 +160,19 @@ sub STORE { return $value; } +sub EXISTS { + my ($self, $index) = @_; + return $index < $self->FETCHSIZE; +} + +sub DELETE { + my ($self, $index) = @_; + my @temp = split($sep, $ENV{$$self}); + my $value = splice(@temp, $index, 1, ()); + $ENV{$$self} = join($sep, @temp); + return $value; +} + sub PUSH { my $self = shift; my @temp = split($sep, $ENV{$$self}); @@ -232,4 +244,11 @@ sub FETCH { return $ENV{$$self . ';' . $index}; } +sub EXISTS { + my ($self, $index) = @_; + return $index < $self->FETCHSIZE; +} + +sub DELETE { } + 1; diff --git a/gnu/usr.bin/perl/lib/Exporter.pm b/gnu/usr.bin/perl/lib/Exporter.pm index 9e1c1ead7f6..cd51828847e 100644 --- a/gnu/usr.bin/perl/lib/Exporter.pm +++ b/gnu/usr.bin/perl/lib/Exporter.pm @@ -9,12 +9,9 @@ require 5.006; our $Debug = 0; our $ExportLevel = 0; our $Verbose ||= 0; -our $VERSION = '5.63'; +our $VERSION = '5.64_01'; our (%Cache); -# Carp 1.05+ does this now for us, but we may be running with an old Carp -$Carp::Internal{Exporter}++; - sub as_heavy { require Exporter::Heavy; # Unfortunately, this does not work if the caller is aliased as *name = \&foo diff --git a/gnu/usr.bin/perl/lib/ExtUtils/typemap b/gnu/usr.bin/perl/lib/ExtUtils/typemap index 2c35437e34c..f88858762d5 100644 --- a/gnu/usr.bin/perl/lib/ExtUtils/typemap +++ b/gnu/usr.bin/perl/lib/ExtUtils/typemap @@ -149,7 +149,7 @@ T_REF_IV_PTR ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\", \"$ntype\") T_PTROBJ - if (sv_derived_from($arg, \"${ntype}\")) { + if (SvROK($arg) && sv_derived_from($arg, \"${ntype}\")) { IV tmp = SvIV((SV*)SvRV($arg)); $var = INT2PTR($type,tmp); } diff --git a/gnu/usr.bin/perl/lib/File/Basename.pm b/gnu/usr.bin/perl/lib/File/Basename.pm index b3fe0ac6e59..d842844daf1 100644 --- a/gnu/usr.bin/perl/lib/File/Basename.pm +++ b/gnu/usr.bin/perl/lib/File/Basename.pm @@ -37,13 +37,13 @@ is equivalent to the original path for all systems but VMS. package File::Basename; -# A bit of juggling to insure that C<use re 'taint';> always works, since # File::Basename is used during the Perl build, when the re extension may -# not be available. +# not be available, but we only actually need it if running under tainting. BEGIN { - unless (eval { require re; }) - { eval ' sub re::import { $^H |= 0x00100000; } ' } # HINT_RE_TAINT - import re 'taint'; + if (${^TAINT}) { + require re; + re->import('taint'); + } } @@ -54,7 +54,7 @@ our(@ISA, @EXPORT, $VERSION, $Fileparse_fstype, $Fileparse_igncase); require Exporter; @ISA = qw(Exporter); @EXPORT = qw(fileparse fileparse_set_fstype basename dirname); -$VERSION = "2.77"; +$VERSION = "2.78"; fileparse_set_fstype($^O); diff --git a/gnu/usr.bin/perl/lib/File/Copy.pm b/gnu/usr.bin/perl/lib/File/Copy.pm index e1d77244b9b..eed6a53195b 100644 --- a/gnu/usr.bin/perl/lib/File/Copy.pm +++ b/gnu/usr.bin/perl/lib/File/Copy.pm @@ -12,10 +12,7 @@ use strict; use warnings; use File::Spec; use Config; -# During perl build, we need File::Copy but Fcntl might not be built yet -# *** not needed for 2.14, only 2.15 -# *** my $Fcntl_loaded = eval q{ use Fcntl qw [O_CREAT O_WRONLY O_TRUNC]; 1 }; -# Similarly Scalar::Util +# During perl build, we need File::Copy but Scalar::Util might not be built yet # And then we need these games to avoid loading overload, as that will # confuse miniperl during the bootstrap of perl. my $Scalar_Util_loaded = eval q{ require Scalar::Util; require overload; 1 }; @@ -25,7 +22,7 @@ sub syscopy; sub cp; sub mv; -$VERSION = '2.14'; +$VERSION = '2.18'; require Exporter; @ISA = qw(Exporter); @@ -51,6 +48,44 @@ if ($^O eq 'MacOS') { if $@ && $^W; } +# Look up the feature settings on VMS using VMS::Feature when available. + +my $use_vms_feature = 0; +BEGIN { + if ($^O eq 'VMS') { + if (eval { local $SIG{__DIE__}; require VMS::Feature; }) { + $use_vms_feature = 1; + } + } +} + +# Need to look up the UNIX report mode. This may become a dynamic mode +# in the future. +sub _vms_unix_rpt { + my $unix_rpt; + if ($use_vms_feature) { + $unix_rpt = VMS::Feature::current("filename_unix_report"); + } else { + my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; + $unix_rpt = $env_unix_rpt =~ /^[ET1]/i; + } + return $unix_rpt; +} + +# Need to look up the EFS character set mode. This may become a dynamic +# mode in the future. +sub _vms_efs { + my $efs; + if ($use_vms_feature) { + $efs = VMS::Feature::current("efs_charset"); + } else { + my $env_efs = $ENV{'DECC$EFS_CHARSET'} || ''; + $efs = $env_efs =~ /^[ET1]/i; + } + return $efs; +} + + sub _catname { my($from, $to) = @_; if (not defined &basename) { @@ -115,7 +150,7 @@ sub copy { my @fs = stat($from); if (@fs) { my @ts = stat($to); - if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) { + if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1] && !-p $from) { carp("'$from' and '$to' are identical (not copied)"); return 0; } @@ -141,14 +176,36 @@ sub copy { if (! -d $to && ! -d $from) { + my $vms_efs = _vms_efs(); + my $unix_rpt = _vms_unix_rpt(); + my $unix_mode = 0; + my $from_unix = 0; + $from_unix = 1 if ($from =~ /^\.\.?$/); + my $from_vms = 0; + $from_vms = 1 if ($from =~ m#[\[<\]]#); + + # Need to know if we are in Unix mode. + if ($from_vms == $from_unix) { + $unix_mode = $unix_rpt; + } else { + $unix_mode = $from_unix; + } + # VMS has sticky defaults on extensions, which means that # if there is a null extension on the destination file, it # will inherit the extension of the source file # So add a '.' for a null extension. - $copy_to = VMS::Filespec::vmsify($to); + # In unix_rpt mode, the trailing dot should not be added. + + if ($vms_efs) { + $copy_to = $to; + } else { + $copy_to = VMS::Filespec::vmsify($to); + } my ($vol, $dirs, $file) = File::Spec->splitpath($copy_to); - $file = $file . '.' unless ($file =~ /(?<!\^)\./); + $file = $file . '.' + unless (($file =~ /(?<!\^)\./) || $unix_rpt); $copy_to = File::Spec->catpath($vol, $dirs, $file); # Get rid of the old versions to be like UNIX @@ -156,7 +213,7 @@ sub copy { } } - return syscopy($from, $copy_to); + return syscopy($from, $copy_to) || 0; } my $closefrom = 0; @@ -168,11 +225,9 @@ sub copy { if ($from_a_handle) { $from_h = $from; } else { - $from = _protect($from) if $from =~ /^\s/s; - $from_h = \do { local *FH }; open $from_h, "<", $from or goto fail_open1; binmode $from_h or die "($!,$^E)"; - $closefrom = 1; + $closefrom = 1; } # Seems most logical to do this here, in case future changes would want to @@ -187,10 +242,9 @@ sub copy { if ($to_a_handle) { $to_h = $to; } else { - $to = _protect($to) if $to =~ /^\s/s; - $to_h = \do { local *FH }; - open $to_h, ">", $to or goto fail_open2; - binmode $to_h or die "($!,$^E)"; + $to_h = \do { local *FH }; # XXX is this line obsolete? + open $to_h, ">", $to or goto fail_open2; + binmode $to_h or die "($!,$^E)"; $closeto = 1; } @@ -231,10 +285,50 @@ sub copy { return 0; } -sub move { - croak("Usage: move(FROM, TO) ") unless @_ == 2; - +sub cp { my($from,$to) = @_; + my(@fromstat) = stat $from; + my(@tostat) = stat $to; + my $perm; + + return 0 unless copy(@_) and @fromstat; + + if (@tostat) { + $perm = $tostat[2]; + } else { + $perm = $fromstat[2] & ~(umask || 0); + @tostat = stat $to; + } + # Might be more robust to look for S_I* in Fcntl, but we're + # trying to avoid dependence on any XS-containing modules, + # since File::Copy is used during the Perl build. + $perm &= 07777; + if ($perm & 06000) { + croak("Unable to check setuid/setgid permissions for $to: $!") + unless @tostat; + + if ($perm & 04000 and # setuid + $fromstat[4] != $tostat[4]) { # owner must match + $perm &= ~06000; + } + + if ($perm & 02000 && $> != 0) { # if not root, setgid + my $ok = $fromstat[5] == $tostat[5]; # group must match + if ($ok) { # and we must be in group + $ok = grep { $_ == $fromstat[5] } split /\s+/, $) + } + $perm &= ~06000 unless $ok; + } + } + return 0 unless @tostat; + return 1 if $perm == ($tostat[2] & 07777); + return eval { chmod $perm, $to; } ? 1 : 0; +} + +sub _move { + croak("Usage: move(FROM, TO) ") unless @_ == 3; + + my($from,$to,$fallback) = @_; my($fromsz,$tosz1,$tomt1,$tosz2,$tomt2,$sts,$ossts); @@ -253,14 +347,37 @@ sub move { if (-$^O eq 'VMS' && -e $from) { if (! -d $to && ! -d $from) { + + my $vms_efs = _vms_efs(); + my $unix_rpt = _vms_unix_rpt(); + my $unix_mode = 0; + my $from_unix = 0; + $from_unix = 1 if ($from =~ /^\.\.?$/); + my $from_vms = 0; + $from_vms = 1 if ($from =~ m#[\[<\]]#); + + # Need to know if we are in Unix mode. + if ($from_vms == $from_unix) { + $unix_mode = $unix_rpt; + } else { + $unix_mode = $from_unix; + } + # VMS has sticky defaults on extensions, which means that # if there is a null extension on the destination file, it # will inherit the extension of the source file # So add a '.' for a null extension. - $rename_to = VMS::Filespec::vmsify($to); + # In unix_rpt mode, the trailing dot should not be added. + + if ($vms_efs) { + $rename_to = $to; + } else { + $rename_to = VMS::Filespec::vmsify($to); + } my ($vol, $dirs, $file) = File::Spec->splitpath($rename_to); - $file = $file . '.' unless ($file =~ /(?<!\^)\./); + $file = $file . '.' + unless (($file =~ /(?<!\^)\./) || $unix_rpt); $rename_to = File::Spec->catpath($vol, $dirs, $file); # Get rid of the old versions to be like UNIX @@ -284,7 +401,7 @@ sub move { local $@; eval { local $SIG{__DIE__}; - copy($from,$to) or die; + $fallback->($from,$to) or die; my($atime, $mtime) = (stat($from))[8,9]; utime($atime, $mtime, $to); unlink($from) or die; @@ -299,15 +416,8 @@ sub move { return 0; } -*cp = \© -*mv = \&move; - - -if ($^O eq 'MacOS') { - *_protect = sub { MacPerl::MakeFSSpec($_[0]) }; -} else { - *_protect = sub { "./$_[0]" }; -} +sub move { _move(@_,\©); } +sub mv { _move(@_,\&cp); } # &syscopy is an XSUB under OS/2 unless (defined &syscopy) { @@ -389,6 +499,12 @@ be opened for reading. Likewise, the second argument will be written to (and created if need be). Trying to copy a file on top of itself is a fatal error. +If the destination (second argument) already exists and is a directory, +and the source (first argument) is not a filehandle, then the source +file will be copied into the directory specified by the destination, +using the same base name as the source file. It's a failure to have a +filehandle as the source when the destination is a directory. + B<Note that passing in files as handles instead of names may lead to loss of information on some operating systems; it is recommended that you use file @@ -403,8 +519,15 @@ being written to the second file. The default buffer size depends upon the file, but will generally be the whole file (up to 2MB), or 1k for filehandles that do not reference files (eg. sockets). -You may use the syntax C<use File::Copy "cp"> to get at the -"cp" alias for this function. The syntax is I<exactly> the same. +You may use the syntax C<use File::Copy "cp"> to get at the C<cp> +alias for this function. The syntax is I<exactly> the same. The +behavior is nearly the same as well: as of version 2.15, <cp> will +preserve the source file's permission bits like the shell utility +C<cp(1)> would do, while C<copy> uses the default permissions for the +target file (which may depend on the process' C<umask>, file +ownership, inherited ACLs, etc.). If an error occurs in setting +permissions, C<cp> will return 0, regardless of whether the file was +successfully copied. =item move X<move> X<mv> X<rename> @@ -420,8 +543,8 @@ the file to the new location and deletes the original. If an error occurs during this copy-and-delete process, you may be left with a (possibly partial) copy of the file under the destination name. -You may use the "mv" alias for this function in the same way that -you may use the "cp" alias for C<copy>. +You may use the C<mv> alias for this function in the same way that +you may use the <cp> alias for C<copy>. =item syscopy X<syscopy> diff --git a/gnu/usr.bin/perl/lib/File/Find.pm b/gnu/usr.bin/perl/lib/File/Find.pm index eddedbd354a..e72f3e32b30 100644 --- a/gnu/usr.bin/perl/lib/File/Find.pm +++ b/gnu/usr.bin/perl/lib/File/Find.pm @@ -3,7 +3,7 @@ use 5.006; use strict; use warnings; use warnings::register; -our $VERSION = '1.14'; +our $VERSION = '1.15'; require Exporter; require Cwd; @@ -217,7 +217,7 @@ through a collection of variables. =back The above variables have all been localized and may be changed without -effecting data outside of the wanted function. +affecting data outside of the wanted function. For example, when examining the file F</some/path/foo.ext> you will have: @@ -448,7 +448,7 @@ sub contract_name { my $abs_name= $cdir . $fn; if (substr($fn,0,3) eq '../') { - 1 while $abs_name =~ s!/[^/]*/\.\./!/!; + 1 while $abs_name =~ s!/[^/]*/\.\./+!/!; } return $abs_name; diff --git a/gnu/usr.bin/perl/lib/File/stat.pm b/gnu/usr.bin/perl/lib/File/stat.pm index d84500c1ace..bdf3aad52a2 100644 --- a/gnu/usr.bin/perl/lib/File/stat.pm +++ b/gnu/usr.bin/perl/lib/File/stat.pm @@ -3,23 +3,170 @@ use 5.006; use strict; use warnings; +use warnings::register; +use Carp; + +BEGIN { *warnif = \&warnings::warnif } our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS); -our $VERSION = '1.01'; +our $VERSION = '1.02'; +my @fields; BEGIN { use Exporter (); @EXPORT = qw(stat lstat); - @EXPORT_OK = qw( $st_dev $st_ino $st_mode + @fields = qw( $st_dev $st_ino $st_mode $st_nlink $st_uid $st_gid $st_rdev $st_size $st_atime $st_mtime $st_ctime $st_blksize $st_blocks ); - %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] ); + @EXPORT_OK = ( @fields, "stat_cando" ); + %EXPORT_TAGS = ( FIELDS => [ @fields, @EXPORT ] ); +} +use vars @fields; + +use Fcntl qw(S_IRUSR S_IWUSR S_IXUSR); + +BEGIN { + # These constants will croak on use if the platform doesn't define + # them. It's important to avoid inflicting that on the user. + no strict 'refs'; + for (qw(suid sgid svtx)) { + my $val = eval { &{"Fcntl::S_I\U$_"} }; + *{"_$_"} = defined $val ? sub { $_[0] & $val ? 1 : "" } : sub { "" }; + } + for (qw(SOCK CHR BLK REG DIR FIFO LNK)) { + *{"S_IS$_"} = defined eval { &{"Fcntl::S_IF$_"} } + ? \&{"Fcntl::S_IS$_"} : sub { "" }; + } +} + +# from doio.c +sub _ingroup { + + $^O eq "MacOS" and return 1; + + my ($gid, $eff) = @_; + + # I am assuming that since VMS doesn't have getgroups(2), $) will + # always only contain a single entry. + $^O eq "VMS" and return $_[0] == $); + + my ($egid, @supp) = split " ", $); + my ($rgid) = split " ", $(; + + $gid == ($eff ? $egid : $rgid) and return 1; + grep $gid == $_, @supp and return 1; + + return ""; +} + +# VMS uses the Unix version of the routine, even though this is very +# suboptimal. VMS has a permissions structure that doesn't really fit +# into struct stat, and unlike on Win32 the normal -X operators respect +# that, but unfortunately by the time we get here we've already lost the +# information we need. It looks to me as though if we were to preserve +# the st_devnam entry of vmsish.h's fake struct stat (which actually +# holds the filename) it might be possible to do this right, but both +# getting that value out of the struct (perl's stat doesn't return it) +# and interpreting it later would require this module to have an XS +# component (at which point we might as well just call Perl_cando and +# have done with it). + +if (grep $^O eq $_, qw/os2 MSWin32 dos/) { + + # from doio.c + *cando = sub { ($_[0][2] & $_[1]) ? 1 : "" }; } -use vars @EXPORT_OK; +else { + + # from doio.c + *cando = sub { + my ($s, $mode, $eff) = @_; + my $uid = $eff ? $> : $<; + + $^O ne "VMS" and $uid == 0 and return 1; + + my ($stmode, $stuid, $stgid) = @$s[2,4,5]; + + # This code basically assumes that the rwx bits of the mode are + # the 0777 bits, but so does Perl_cando. + if ($stuid == $uid) { + $stmode & $mode and return 1; + } + elsif (_ingroup($stgid, $eff)) { + $stmode & ($mode >> 3) and return 1; + } + else { + $stmode & ($mode >> 6) and return 1; + } + return ""; + }; +} + +# alias for those who don't like objects +*stat_cando = \&cando; + +my %op = ( + r => sub { cando($_[0], S_IRUSR, 1) }, + w => sub { cando($_[0], S_IWUSR, 1) }, + x => sub { cando($_[0], S_IXUSR, 1) }, + o => sub { $_[0][4] == $> }, + + R => sub { cando($_[0], S_IRUSR, 0) }, + W => sub { cando($_[0], S_IWUSR, 0) }, + X => sub { cando($_[0], S_IXUSR, 0) }, + O => sub { $_[0][4] == $< }, + + e => sub { 1 }, + z => sub { $_[0][7] == 0 }, + s => sub { $_[0][7] }, + + f => sub { S_ISREG ($_[0][2]) }, + d => sub { S_ISDIR ($_[0][2]) }, + l => sub { S_ISLNK ($_[0][2]) }, + p => sub { S_ISFIFO($_[0][2]) }, + S => sub { S_ISSOCK($_[0][2]) }, + b => sub { S_ISBLK ($_[0][2]) }, + c => sub { S_ISCHR ($_[0][2]) }, + + u => sub { _suid($_[0][2]) }, + g => sub { _sgid($_[0][2]) }, + k => sub { _svtx($_[0][2]) }, + + M => sub { ($^T - $_[0][9] ) / 86400 }, + C => sub { ($^T - $_[0][10]) / 86400 }, + A => sub { ($^T - $_[0][8] ) / 86400 }, +); + +use constant HINT_FILETEST_ACCESS => 0x00400000; + +# we need fallback=>1 or stringifying breaks +use overload + fallback => 1, + -X => sub { + my ($s, $op) = @_; + + if (index "rwxRWX", $op) { + (caller 0)[8] & HINT_FILETEST_ACCESS + and warnif("File::stat ignores use filetest 'access'"); + + $^O eq "VMS" and warnif("File::stat ignores VMS ACLs"); + + # It would be nice to have a warning about using -l on a + # non-lstat, but that would require an extra member in the + # object. + } + + if ($op{$op}) { + return $op{$op}->($_[0]); + } + else { + croak "-$op is not implemented on a File::stat object"; + } + }; # Class::Struct forbids use of @ISA sub import { goto &Exporter::import } @@ -47,7 +194,7 @@ sub lstat ($) { populate(CORE::lstat(shift)) } sub stat ($) { my $arg = shift; my $st = populate(CORE::stat $arg); - return $st if $st; + return $st if defined $st; my $fh; { local $!; @@ -74,6 +221,15 @@ File::stat - by-name interface to Perl's built-in stat() functions print "$file is executable with lotsa links\n"; } + if ( -x $st ) { + print "$file is executable\n"; + } + + use Fcntl "S_IRUSR"; + if ( $st->cando(S_IRUSR, 1) ) { + print "My effective uid can read $file\n"; + } + use File::stat qw(:FIELDS); stat($file) or die "No $file: $!"; if ( ($st_mode & 0111) && ($st_nlink > 1) ) { @@ -102,6 +258,23 @@ blksize, and blocks. +As of version 1.02 (provided with perl 5.12) the object provides C<"-X"> +overloading, so you can call filetest operators (C<-f>, C<-x>, and so +on) on it. It also provides a C<< ->cando >> method, called like + + $st->cando( ACCESS, EFFECTIVE ) + +where I<ACCESS> is one of C<S_IRUSR>, C<S_IWUSR> or C<S_IXUSR> from the +L<Fcntl|Fcntl> module, and I<EFFECTIVE> indicates whether to use +effective (true) or real (false) ids. The method interprets the C<mode>, +C<uid> and C<gid> fields, and returns whether or not the current process +would be allowed the specified access. + +If you don't want to use the objects, you may import the C<< ->cando >> +method into your namespace as a regular function called C<stat_cando>. +This takes an arrayref containing the return values of C<stat> or +C<lstat> as its first argument, and interprets it for you. + You may also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. (Note that this still overrides your stat() and lstat() functions.) Access these fields as @@ -129,6 +302,40 @@ and undocumented populate() function with CORE::stat(): my $stat_obj = File::stat::populate(CORE::stat(_)); +=head1 ERRORS + +=over 4 + +=item -%s is not implemented on a File::stat object + +The filetest operators C<-t>, C<-T> and C<-B> are not implemented, as +they require more information than just a stat buffer. + +=back + +=head1 WARNINGS + +These can all be disabled with + + no warnings "File::stat"; + +=over 4 + +=item File::stat ignores use filetest 'access' + +You have tried to use one of the C<-rwxRWX> filetests with C<use +filetest 'access'> in effect. C<File::stat> will ignore the pragma, and +just use the information in the C<mode> member as usual. + +=item File::stat ignores VMS ACLs + +VMS systems have a permissions structure that cannot be completely +represented in a stat buffer, and unlike on other systems the builtin +filetest operators respect this. The C<File::stat> overloads, however, +do not, since the information required is not available. + +=back + =head1 NOTE While this class is currently implemented using the Class::Struct diff --git a/gnu/usr.bin/perl/lib/Pod/Functions.pm b/gnu/usr.bin/perl/lib/Pod/Functions.pm index 0e250cf0b50..5181c3990bf 100644 --- a/gnu/usr.bin/perl/lib/Pod/Functions.pm +++ b/gnu/usr.bin/perl/lib/Pod/Functions.pm @@ -67,7 +67,7 @@ L<perlfunc/"Perl Functions by Category"> section. =cut -our $VERSION = '1.03'; +our $VERSION = '1.04'; require Exporter; @@ -171,7 +171,7 @@ chdir File change your current working directory chmod File changes the permissions on a list of files chomp String remove a trailing record separator from a string chop String remove the last character from a string -chown File change the owership on a list of files +chown File change the ownership on a list of files chr String get character this number represents chroot File make directory new root for path lookups close I/O close file (or pipe or socket) handle @@ -248,7 +248,7 @@ last Flow exit a block prematurely lc String return lower-case version of a string lcfirst String return a string with just the next letter in lower case length String return the number of bytes in a string -link File create a hard link in the filesytem +link File create a hard link in the filesystem listen Socket register your socket as a server local Misc,Namespace create a temporary value for a global variable (dynamic scoping) localtime Time convert UNIX time into record or string using local time @@ -339,7 +339,7 @@ srand Math seed the random number generator stat File get a file's status information study Regexp optimize input data for repeated searches sub Flow declare a subroutine, possibly anonymously -substr String get or alter a portion of a stirng +substr String get or alter a portion of a string symlink File create a symbolic link to a file syscall I/O,Binary execute an arbitrary system call sysopen File open a file, pipe, or descriptor diff --git a/gnu/usr.bin/perl/lib/Pod/Html.pm b/gnu/usr.bin/perl/lib/Pod/Html.pm index 99f95a92108..6174dd74576 100644 --- a/gnu/usr.bin/perl/lib/Pod/Html.pm +++ b/gnu/usr.bin/perl/lib/Pod/Html.pm @@ -1575,7 +1575,9 @@ sub process_text1($$;$$){ # E<x> - convert to character $$rstr =~ s/^([^>]*)>//; my $escape = $1; - $escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i; + $escape =~ s/^0?x([\dA-F]+)$/#x$1/i + or $escape =~ s/^0([0-7]+)$/'#'.oct($1)/ei + or $escape =~ s/^(\d+)$/#$1/; $res = "&$escape;"; } elsif( $func eq 'F' ){ diff --git a/gnu/usr.bin/perl/lib/Search/Dict.pm b/gnu/usr.bin/perl/lib/Search/Dict.pm index 199fa5f9b41..5cdd2f42c7a 100644 --- a/gnu/usr.bin/perl/lib/Search/Dict.pm +++ b/gnu/usr.bin/perl/lib/Search/Dict.pm @@ -35,7 +35,7 @@ If I<$fold> is true, ignore case. The default is to honour case. If there are only three arguments and the third argument is a hash reference, the keys of that hash can have values C<dict>, C<fold>, and -C<comp> or C<xfrm> (see below), and their correponding values will be +C<comp> or C<xfrm> (see below), and their corresponding values will be used as the parameters. If a comparison subroutine (comp) is defined, it must return less than zero, diff --git a/gnu/usr.bin/perl/lib/Term/ReadLine.pm b/gnu/usr.bin/perl/lib/Term/ReadLine.pm index a8116af5e74..29acb849015 100644 --- a/gnu/usr.bin/perl/lib/Term/ReadLine.pm +++ b/gnu/usr.bin/perl/lib/Term/ReadLine.pm @@ -303,7 +303,7 @@ sub get_line { package Term::ReadLine; # So late to allow the above code be defined? -our $VERSION = '1.04'; +our $VERSION = '1.05'; my ($which) = exists $ENV{PERL_RL} ? split /\s+/, $ENV{PERL_RL} : undef; if ($which) { @@ -311,6 +311,9 @@ if ($which) { eval "use Term::ReadLine::Gnu;"; } elsif ($which =~ /\bperl\b/i) { eval "use Term::ReadLine::Perl;"; + } elsif ($which =~ /^(Stub|TermCap|Tk)$/) { + # it is already in memory to avoid false exception as seen in: + # PERL_RL=Stub perl -e'$SIG{__DIE__} = sub { print @_ }; require Term::ReadLine' } else { eval "use Term::ReadLine::$which;"; } diff --git a/gnu/usr.bin/perl/lib/Tie/Scalar.pm b/gnu/usr.bin/perl/lib/Tie/Scalar.pm index 9bf03f9105c..24e4ae79c3c 100644 --- a/gnu/usr.bin/perl/lib/Tie/Scalar.pm +++ b/gnu/usr.bin/perl/lib/Tie/Scalar.pm @@ -1,6 +1,6 @@ package Tie::Scalar; -our $VERSION = '1.01'; +our $VERSION = '1.02'; =head1 NAME @@ -73,6 +73,18 @@ destruction of an instance. =back +=head2 Tie::Scalar vs Tie::StdScalar + +C<< Tie::Scalar >> provides all the necessary methods, but one should realize +they do not do anything useful. Calling C<< Tie::Scalar::FETCH >> or +C<< Tie::Scalar::STORE >> results in a (trappable) croak. And if you inherit +from C<< Tie::Scalar >>, you I<must> provide either a C<< new >> or a +C<< TIESCALAR >> method. + +If you are looking for a class that does everything for you you don't +define yourself, use the C<< Tie::StdScalar >> class, not the +C<< Tie::Scalar >> one. + =head1 MORE INFORMATION The L<perltie> section uses a good example of tying scalars by associating @@ -92,9 +104,20 @@ sub new { sub TIESCALAR { my $pkg = shift; - if ($pkg->can('new') and $pkg ne __PACKAGE__) { - warnings::warnif("WARNING: calling ${pkg}->new since ${pkg}->TIESCALAR is missing"); - $pkg->new(@_); + my $pkg_new = $pkg -> can ('new'); + + if ($pkg_new and $pkg ne __PACKAGE__) { + my $my_new = __PACKAGE__ -> can ('new'); + if ($pkg_new == $my_new) { + # + # Prevent recursion + # + croak "$pkg must define either a TIESCALAR() or a new() method"; + } + + warnings::warnif ("WARNING: calling ${pkg}->new since " . + "${pkg}->TIESCALAR is missing"); + $pkg -> new (@_); } else { croak "$pkg doesn't define a TIESCALAR method"; diff --git a/gnu/usr.bin/perl/lib/UNIVERSAL.pm b/gnu/usr.bin/perl/lib/UNIVERSAL.pm index 3a7b53ef61b..e30f5a7eda0 100644 --- a/gnu/usr.bin/perl/lib/UNIVERSAL.pm +++ b/gnu/usr.bin/perl/lib/UNIVERSAL.pm @@ -1,6 +1,6 @@ package UNIVERSAL; -our $VERSION = '1.05'; +our $VERSION = '1.06'; # UNIVERSAL should not contain any extra subs/methods beyond those # that it exists to define. The use of Exporter below is a historical @@ -15,6 +15,12 @@ require Exporter; # anything unless called on UNIVERSAL. sub import { return unless $_[0] eq __PACKAGE__; + return unless @_ > 1; + require warnings; + warnings::warnif( + 'deprecated', + 'UNIVERSAL->import is deprecated and will be removed in a future perl', + ); goto &Exporter::import; } @@ -141,7 +147,7 @@ I<undef>. This includes methods inherited or imported by C<$obj>, C<CLASS>, or C<VAL>. C<can> cannot know whether an object will be able to provide a method through -AUTOLOAD (unless the object's class has overriden C<can> appropriately), so a +AUTOLOAD (unless the object's class has overridden C<can> appropriately), so a return value of I<undef> does not necessarily mean the object will not be able to handle the method call. To get around this some module authors use a forward declaration (see L<perlsub>) for methods they will handle via AUTOLOAD. For @@ -159,7 +165,9 @@ block or C<blessed> if you need to be extra paranoid. C<VERSION> will return the value of the variable C<$VERSION> in the package the object is blessed into. If C<REQUIRE> is given then it will do a comparison and die if the package version is not -greater than or equal to C<REQUIRE>. +greater than or equal to C<REQUIRE>. Both C<$VERSION> or C<REQUIRE> +must be "lax" version numbers (as defined by the L<version> module) +or C<VERSION> will die with an error. C<VERSION> can be called as either a class (static) method or an object method. @@ -181,7 +189,8 @@ available to your program (and you should not do so). None by default. You may request the import of three functions (C<isa>, C<can>, and C<VERSION>), -however it is usually harmful to do so. Please don't do this in new code. +B<but this feature is deprecated and will be removed>. Please don't do this in +new code. For example, previous versions of this documentation suggested using C<isa> as a function to determine the type of a reference: diff --git a/gnu/usr.bin/perl/lib/abbrev.pl b/gnu/usr.bin/perl/lib/abbrev.pl index c505a6f28bd..cd20063f003 100644 --- a/gnu/usr.bin/perl/lib/abbrev.pl +++ b/gnu/usr.bin/perl/lib/abbrev.pl @@ -7,6 +7,8 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. diff --git a/gnu/usr.bin/perl/lib/bigfloat.pl b/gnu/usr.bin/perl/lib/bigfloat.pl index 8c28abdcd1d..dd0bc05af2f 100644 --- a/gnu/usr.bin/perl/lib/bigfloat.pl +++ b/gnu/usr.bin/perl/lib/bigfloat.pl @@ -3,12 +3,14 @@ require "bigint.pl"; # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternative: Math::BigFloat -# + # Arbitrary length float math package # # by Mark Biggar diff --git a/gnu/usr.bin/perl/lib/bigint.pl b/gnu/usr.bin/perl/lib/bigint.pl index bd1d91f8229..d28f0e27a0b 100644 --- a/gnu/usr.bin/perl/lib/bigint.pl +++ b/gnu/usr.bin/perl/lib/bigint.pl @@ -5,9 +5,11 @@ package bigint; # # In particular, this should not be used as an example of modern Perl # programming techniques. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # Suggested alternative: Math::BigInt -# + # arbitrary size integer math package # # by Mark Biggar diff --git a/gnu/usr.bin/perl/lib/cacheout.pl b/gnu/usr.bin/perl/lib/cacheout.pl index d2669a1cfa8..368e98ee21d 100644 --- a/gnu/usr.bin/perl/lib/cacheout.pl +++ b/gnu/usr.bin/perl/lib/cacheout.pl @@ -1,6 +1,8 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. diff --git a/gnu/usr.bin/perl/lib/complete.pl b/gnu/usr.bin/perl/lib/complete.pl index 925ce86e5da..2fb3b33b85e 100644 --- a/gnu/usr.bin/perl/lib/complete.pl +++ b/gnu/usr.bin/perl/lib/complete.pl @@ -2,12 +2,14 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternative: Term::Complete -# + ;# @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91 ;# ;# Author: Wayne Thompson diff --git a/gnu/usr.bin/perl/lib/ctime.pl b/gnu/usr.bin/perl/lib/ctime.pl index 6a3f2959686..1b91ec289f5 100644 --- a/gnu/usr.bin/perl/lib/ctime.pl +++ b/gnu/usr.bin/perl/lib/ctime.pl @@ -2,11 +2,14 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternative: the POSIX ctime function + ;# ;# Waldemar Kebsch, Federal Republic of Germany, November 1988 ;# kebsch.pad@nixpbe.UUCP diff --git a/gnu/usr.bin/perl/lib/diagnostics.pm b/gnu/usr.bin/perl/lib/diagnostics.pm index 7af5efa1778..721b466fd05 100644 --- a/gnu/usr.bin/perl/lib/diagnostics.pm +++ b/gnu/usr.bin/perl/lib/diagnostics.pm @@ -185,7 +185,7 @@ use 5.009001; use Carp; $Carp::Internal{__PACKAGE__.""}++; -our $VERSION = 1.17; +our $VERSION = '1.19'; our $DEBUG; our $VERBOSE; our $PRETTY; @@ -222,6 +222,7 @@ my $WHOAMI = ref bless []; # nobody's business, prolly not even mine local $| = 1; my $_; +local $.; my $standalone; my(%HTML_2_Troff, %HTML_2_Latin_1, %HTML_2_ASCII_7); @@ -377,7 +378,7 @@ my %msg; # strip formatting directives from =item line $header =~ s/[A-Z]<(.*?)>/$1/g; - my @toks = split( /(%l?[dx]|%c|%(?:\.\d+)?s)/, $header ); + my @toks = split( /(%l?[dx]|%c|%(?:\.\d+)?[fs])/, $header ); if (@toks > 1) { my $conlen = 0; for my $i (0..$#toks){ @@ -386,7 +387,7 @@ my %msg; $toks[$i] = '.'; } elsif( $toks[$i] eq '%d' ){ $toks[$i] = '\d+'; - } elsif( $toks[$i] eq '%s' ){ + } elsif( $toks[$i] =~ '^%(?:s|.*f)$' ){ $toks[$i] = $i == $#toks ? '.*' : '.*?'; } elsif( $toks[$i] =~ '%.(\d+)s' ){ $toks[$i] = ".{$1}"; diff --git a/gnu/usr.bin/perl/lib/dotsh.pl b/gnu/usr.bin/perl/lib/dotsh.pl index 810ebc4d605..2ae88ba43de 100644 --- a/gnu/usr.bin/perl/lib/dotsh.pl +++ b/gnu/usr.bin/perl/lib/dotsh.pl @@ -3,11 +3,12 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # -# # Author: Charles Collins # # Description: @@ -31,6 +32,7 @@ # &dotsh ('/foo/bar'); # &dotsh ('/foo/bar arg1 ... argN'); # + sub dotsh { local(@sh) = @_; local($tmp,$key,$shell,$command,$args,$vars) = ''; diff --git a/gnu/usr.bin/perl/lib/find.pl b/gnu/usr.bin/perl/lib/find.pl index ee5dc5d1506..f79decf8372 100644 --- a/gnu/usr.bin/perl/lib/find.pl +++ b/gnu/usr.bin/perl/lib/find.pl @@ -1,3 +1,8 @@ +# This library is deprecated and unmaintained. It is included for +# compatibility with Perl 4 scripts which may use it, but it will be +# removed in a future version of Perl. Please use the File::Find module +# instead. + # Usage: # require "find.pl"; # @@ -10,11 +15,11 @@ # to $dir when the function is called. The function may # set $prune to prune the tree. # -# This library is primarily for find2perl, which, when fed +# For example, # -# find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune +# find / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune # -# spits out something like this +# corresponds to this # # sub wanted { # /^\.nfs.*$/ && diff --git a/gnu/usr.bin/perl/lib/finddepth.pl b/gnu/usr.bin/perl/lib/finddepth.pl index bfa44bb1bc9..331247ae29d 100644 --- a/gnu/usr.bin/perl/lib/finddepth.pl +++ b/gnu/usr.bin/perl/lib/finddepth.pl @@ -1,3 +1,8 @@ +# This library is deprecated and unmaintained. It is included for +# compatibility with Perl 4 scripts which may use it, but it will be +# removed in a future version of Perl. Please use the File::Find module +# instead. + # Usage: # require "finddepth.pl"; # @@ -10,11 +15,11 @@ # to $dir when the function is called. The function may # set $prune to prune the tree. # -# This library is primarily for find2perl, which, when fed +# For example, # -# find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune +# find / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune # -# spits out something like this +# corresponds to this # # sub wanted { # /^\.nfs.*$/ && diff --git a/gnu/usr.bin/perl/lib/getcwd.pl b/gnu/usr.bin/perl/lib/getcwd.pl index eca6ba1127e..fcca2ced80d 100644 --- a/gnu/usr.bin/perl/lib/getcwd.pl +++ b/gnu/usr.bin/perl/lib/getcwd.pl @@ -2,12 +2,13 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. -# +# This legacy library is deprecated and will be removed in a future +# release of perl. # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternative: Cwd -# + # # Usage: $cwd = &getcwd; diff --git a/gnu/usr.bin/perl/lib/getopt.pl b/gnu/usr.bin/perl/lib/getopt.pl index 77d8d899a4a..343921f39cc 100644 --- a/gnu/usr.bin/perl/lib/getopt.pl +++ b/gnu/usr.bin/perl/lib/getopt.pl @@ -2,12 +2,14 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternatives: Getopt::Long or Getopt::Std -# + ;# Process single-character switches with switch clustering. Pass one argument ;# which is a string containing all switches that take an argument. For each ;# switch found, sets $opt_x (where x is the switch name) to the value of the diff --git a/gnu/usr.bin/perl/lib/getopts.pl b/gnu/usr.bin/perl/lib/getopts.pl index e30820a3189..b2aa5cb60e1 100644 --- a/gnu/usr.bin/perl/lib/getopts.pl +++ b/gnu/usr.bin/perl/lib/getopts.pl @@ -7,7 +7,7 @@ # programming techniques. # # Suggested alternatives: Getopt::Long or Getopt::Std -# + ;# Usage: ;# do Getopts('a:bc'); # -a takes arg. -b & -c not. Sets opt_* as a ;# # side effect. diff --git a/gnu/usr.bin/perl/lib/importenv.pl b/gnu/usr.bin/perl/lib/importenv.pl index 0401127f186..865a22652d6 100644 --- a/gnu/usr.bin/perl/lib/importenv.pl +++ b/gnu/usr.bin/perl/lib/importenv.pl @@ -1,3 +1,8 @@ +# This library is no longer being maintained, and is included for backward +# compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. + ;# This file, when interpreted, pulls the environment into normal variables. ;# Usage: ;# require 'importenv.pl'; diff --git a/gnu/usr.bin/perl/lib/look.pl b/gnu/usr.bin/perl/lib/look.pl index ccc9b6162ae..f2a4e09dd6b 100644 --- a/gnu/usr.bin/perl/lib/look.pl +++ b/gnu/usr.bin/perl/lib/look.pl @@ -2,10 +2,12 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. -# + ;# Sets file position in FILEHANDLE to be first line greater than or equal ;# (stringwise) to $key. Pass flags for dictionary order and case folding. diff --git a/gnu/usr.bin/perl/lib/newgetopt.pl b/gnu/usr.bin/perl/lib/newgetopt.pl index 1de6a6ebb18..d6d8b0b07bf 100644 --- a/gnu/usr.bin/perl/lib/newgetopt.pl +++ b/gnu/usr.bin/perl/lib/newgetopt.pl @@ -3,6 +3,8 @@ # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. # It is now just a wrapper around the Getopt::Long module. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. diff --git a/gnu/usr.bin/perl/lib/open2.pl b/gnu/usr.bin/perl/lib/open2.pl index 8cf08c2e8bd..96d80d7b26a 100644 --- a/gnu/usr.bin/perl/lib/open2.pl +++ b/gnu/usr.bin/perl/lib/open2.pl @@ -1,3 +1,6 @@ +# This legacy library is deprecated and will be removed in a future +# release of perl. +# # This is a compatibility interface to IPC::Open2. New programs should # do # diff --git a/gnu/usr.bin/perl/lib/open3.pl b/gnu/usr.bin/perl/lib/open3.pl index 7fcc9318610..9a387eb9a01 100644 --- a/gnu/usr.bin/perl/lib/open3.pl +++ b/gnu/usr.bin/perl/lib/open3.pl @@ -1,3 +1,6 @@ +# This legacy library is deprecated and will be removed in a future +# release of perl. +# # This is a compatibility interface to IPC::Open3. New programs should # do # diff --git a/gnu/usr.bin/perl/lib/overload.pm b/gnu/usr.bin/perl/lib/overload.pm index f83191b5cd0..7d09d69e055 100644 --- a/gnu/usr.bin/perl/lib/overload.pm +++ b/gnu/usr.bin/perl/lib/overload.pm @@ -1,6 +1,6 @@ package overload; -our $VERSION = '1.07'; +our $VERSION = '1.10'; sub nil {} @@ -9,6 +9,7 @@ sub OVERLOAD { my %arg = @_; my ($sub, $fb); $ {$package . "::OVERLOAD"}{dummy}++; # Register with magic by touching. + $fb = ${$package . "::()"}; # preserve old fallback value RT#68196 *{$package . "::()"} = \&nil; # Make it findable via fetchmethod. for (keys %arg) { if ($_ eq 'fallback') { @@ -104,6 +105,10 @@ sub AddrRef { sub mycan { # Real can would leave stubs. my ($package, $meth) = @_; + local $@; + local $!; + require mro; + my $mro = mro::get_linear_isa($package); foreach my $p (@$mro) { my $fqmeth = $p . q{::} . $meth; @@ -130,8 +135,9 @@ sub mycan { # Real can would leave stubs. unary => "neg ! ~", mutators => '++ --', func => "atan2 cos sin exp abs log sqrt int", - conversion => 'bool "" 0+', + conversion => 'bool "" 0+ qr', iterators => '<>', + filetest => "-X", dereferencing => '${} @{} %{} &{} *{}', matching => '~~', special => 'nomethod fallback ='); @@ -394,15 +400,20 @@ floating-point-like types one should follow the same semantic. If C<int> is unavailable, it can be autogenerated using the overloading of C<0+>. -=item * I<Boolean, string and numeric conversion> +=item * I<Boolean, string, numeric and regexp conversions> - 'bool', '""', '0+', + 'bool', '""', '0+', 'qr' -If one or two of these operations are not overloaded, the remaining ones can -be used instead. C<bool> is used in the flow control operators -(like C<while>) and for the ternary C<?:> operation. These functions can -return any arbitrary Perl value. If the corresponding operation for this value -is overloaded too, that operation will be called again with this value. +If one or two of these operations are not overloaded, the remaining ones +can be used instead. C<bool> is used in the flow control operators +(like C<while>) and for the ternary C<?:> operation; C<qr> is used for +the RHS of C<=~> and when an object is interpolated into a regexp. + +C<bool>, C<"">, and C<0+> can return any arbitrary Perl value. If the +corresponding operation for this value is overloaded too, that operation +will be called again with this value. C<qr> must return a compiled +regexp, or a ref to a compiled regexp (such as C<qr//> returns), and any +further overloading on the return value will be ignored. As a special case if the overload returns the object itself then it will be used directly. An overloaded conversion returning the object is @@ -421,6 +432,29 @@ I<globbing> syntax C<E<lt>${var}E<gt>>. B<BUGS> Even in list context, the iterator is currently called only once and with scalar context. +=item * I<File tests> + + "-X" + +This overload is used for all the filetest operators (C<-f>, C<-x> and +so on: see L<perlfunc/-X> for the full list). Even though these are +unary operators, the method will be called with a second argument which +is a single letter indicating which test was performed. Note that the +overload key is the literal string C<"-X">: you can't provide separate +overloads for the different tests. + +Calling an overloaded filetest operator does not affect the stat value +associated with the special filehandle C<_>. It still refers to the +result of the last C<stat>, C<lstat> or unoverloaded filetest. + +If not overloaded, these operators will fall back to the default +behaviour even without C<< fallback => 1 >>. This means that if the +object is a blessed glob or blessed IO ref it will be treated as a +filehandle, otherwise string overloading will be invoked and the result +treated as a filename. + +This overload was introduced in perl 5.12. + =item * I<Matching> The key C<"~~"> allows you to override the smart matching logic used by @@ -489,8 +523,9 @@ A computer-readable form of the above table is available in the hash unary => 'neg ! ~', mutators => '++ --', func => 'atan2 cos sin exp abs log sqrt', - conversion => 'bool "" 0+', + conversion => 'bool "" 0+ qr', iterators => '<>', + filetest => '-X', dereferencing => '${} @{} %{} &{} *{}', matching => '~~', special => 'nomethod fallback =' @@ -663,8 +698,8 @@ is not defined. =item I<Conversion operations> -String, numeric, and boolean conversion are calculated in terms of one -another if not all of them are defined. +String, numeric, boolean and regexp conversions are calculated in terms +of one another if not all of them are defined. =item I<Increment and decrement> diff --git a/gnu/usr.bin/perl/lib/perl5db.pl b/gnu/usr.bin/perl/lib/perl5db.pl index cfe5252ad35..78fe194de5a 100644 --- a/gnu/usr.bin/perl/lib/perl5db.pl +++ b/gnu/usr.bin/perl/lib/perl5db.pl @@ -511,7 +511,7 @@ package DB; BEGIN {eval 'use IO::Handle'}; # Needed for flush only? breaks under miniperl # Debugger for Perl 5.00x; perl5db.pl patch level: -$VERSION = 1.32; +$VERSION = '1.33'; $header = "perl5db.pl version $VERSION"; @@ -949,6 +949,9 @@ sub eval { # + [perl #57016] debugger: o warn=0 die=0 ignored # + Note, but don't use, PERLDBf_SAVESRC # + Fix #7013: lvalue subs not working inside debugger +# Changes: 1.32: Jun 03, 2009 Jonathan Leto <jonathan@leto.net> +# + Fix bug where a key _< with undefined value was put into the symbol table +# + when the $filename variable is not set ######################################################################## =head1 DEBUGGER INITIALIZATION @@ -1053,8 +1056,9 @@ warn( # Do not ;-) ) if 0; +# without threads, $filename is not defined until DB::DB is called foreach my $k (keys (%INC)) { - &share(\$main::{'_<'.$filename}); + &share(\$main::{'_<'.$filename}) if defined $filename; }; # Command-line + PERLLIB: @@ -1846,7 +1850,7 @@ $I_m_init = 1; This gigantic subroutine is the heart of the debugger. Called before every statement, its job is to determine if a breakpoint has been reached, and stop if so; read commands from the user, parse them, and execute -them, and hen send execution off to the next statement. +them, and then send execution off to the next statement. Note that the order in which the commands are processed is very important; some commands earlier in the loop will actually alter the C<$cmd> variable @@ -4831,30 +4835,21 @@ Display the (nested) parentage of the module or object given. sub cmd_i { my $cmd = shift; my $line = shift; - eval { require Class::ISA }; - if ($@) { - &warn( $@ =~ /locate/ - ? "Class::ISA module not found - please install\n" - : $@ ); - } - else { - ISA: - foreach my $isa ( split( /\s+/, $line ) ) { - $evalarg = $isa; - ($isa) = &eval; - no strict 'refs'; - print join( - ', ', - map { # snaffled unceremoniously from Class::ISA - "$_" - . ( - defined( ${"$_\::VERSION"} ) - ? ' ' . ${"$_\::VERSION"} - : undef ) - } Class::ISA::self_and_super_path(ref($isa) || $isa) - ); - print "\n"; - } + foreach my $isa ( split( /\s+/, $line ) ) { + $evalarg = $isa; + ($isa) = &eval; + no strict 'refs'; + print join( + ', ', + map { + "$_" + . ( + defined( ${"$_\::VERSION"} ) + ? ' ' . ${"$_\::VERSION"} + : undef ) + } @{mro::get_linear_isa(ref($isa) || $isa)} + ); + print "\n"; } } ## end sub cmd_i @@ -8179,10 +8174,8 @@ my @pods = qw( lexwarn locale lol - machten macos macosx - mint modinstall modlib mod @@ -8197,7 +8190,6 @@ my @pods = qw( os2 os390 os400 - othrtut packtut plan9 pod @@ -8613,7 +8605,6 @@ If there's only one hit, and it's a package qualifier, and it's not equal to the =cut if ( $text =~ /^[\$@%]/ ) { # symbols (in $package + packages in main) - =pod =over 4 @@ -8637,6 +8628,32 @@ We set the prefix to the item's sigil, and trim off the sigil to get the text to $prefix = substr $text, 0, 1; $text = substr $text, 1; + my @out; + +=pod + +=item * + +We look for the lexical scope above DB::DB and auto-complete lexical variables +if PadWalker could be loaded. + +=cut + + if (not $text =~ /::/ and eval "require PadWalker; 1" and not $@ ) { + my $level = 1; + while (1) { + my @info = caller($level); + $level++; + $level = -1, last + if not @info; + last if $info[3] eq 'DB::DB'; + } + if ($level > 0) { + my $lexicals = PadWalker::peek_my($level); + push @out, grep /^\Q$prefix$text/, keys %$lexicals; + } + } + =pod =item * @@ -8645,7 +8662,7 @@ If the package is C<::> (C<main>), create an empty list; if it's something else, =cut - my @out = map "$prefix$_", grep /^\Q$text/, + push @out, map "$prefix$_", grep /^\Q$text/, ( grep /^_?[a-zA-Z]/, keys %$pack ), ( $pack eq '::' ? () : ( grep /::$/, keys %:: ) ); diff --git a/gnu/usr.bin/perl/lib/pwd.pl b/gnu/usr.bin/perl/lib/pwd.pl index 6b429eb5a68..68b59fcc216 100644 --- a/gnu/usr.bin/perl/lib/pwd.pl +++ b/gnu/usr.bin/perl/lib/pwd.pl @@ -3,12 +3,14 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternative: Cwd -# + ;# $RCSfile: pwd.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:11 $ ;# ;# $Log: pwd.pl,v $ diff --git a/gnu/usr.bin/perl/lib/stat.pl b/gnu/usr.bin/perl/lib/stat.pl index c6682b9df3d..4174d6007d1 100644 --- a/gnu/usr.bin/perl/lib/stat.pl +++ b/gnu/usr.bin/perl/lib/stat.pl @@ -1,8 +1,12 @@ +;# This legacy library is deprecated and will be removed in a future +;# release of perl. +;# ;# Usage: ;# require 'stat.pl'; ;# @ary = stat(foo); ;# $st_dev = @ary[$ST_DEV]; ;# + $ST_DEV = 0 + $[; $ST_INO = 1 + $[; $ST_MODE = 2 + $[; diff --git a/gnu/usr.bin/perl/lib/termcap.pl b/gnu/usr.bin/perl/lib/termcap.pl index f295a2d476b..247a1718da7 100644 --- a/gnu/usr.bin/perl/lib/termcap.pl +++ b/gnu/usr.bin/perl/lib/termcap.pl @@ -2,12 +2,15 @@ # # This library is no longer being maintained, and is included for backward # compatibility with Perl 4 programs which may require it. +# This legacy library is deprecated and will be removed in a future +# release of perl. # # In particular, this should not be used as an example of modern Perl # programming techniques. # # Suggested alternative: Term::Cap # + ;# ;# Usage: ;# require 'ioctl.pl'; diff --git a/gnu/usr.bin/perl/lib/timelocal.pl b/gnu/usr.bin/perl/lib/timelocal.pl index ad322756e38..5e08dad9e34 100644 --- a/gnu/usr.bin/perl/lib/timelocal.pl +++ b/gnu/usr.bin/perl/lib/timelocal.pl @@ -7,6 +7,8 @@ ;# This file has been superseded by the Time::Local library module. ;# It is implemented as a call to that module for backwards compatibility ;# with code written for perl4; new code should use Time::Local directly. +;# This legacy library is deprecated and will be removed in a future +;# release of perl. ;# The current implementation shares with the original the questionable ;# behavior of defining the timelocal() and timegm() functions in the @@ -16,3 +18,4 @@ use Time::Local; *timelocal::cheat = \&Time::Local::cheat; + diff --git a/gnu/usr.bin/perl/lib/version/Internals.pod b/gnu/usr.bin/perl/lib/version/Internals.pod index 5ff365e2762..a4f0543fe16 100644 --- a/gnu/usr.bin/perl/lib/version/Internals.pod +++ b/gnu/usr.bin/perl/lib/version/Internals.pod @@ -1,34 +1,34 @@ =head1 NAME -version::Internal - Perl extension for Version Objects +version::Internals - Perl extension for Version Objects =head1 DESCRIPTION Overloaded version objects for all modern versions of Perl. This documents the internal data representation and underlying code for version.pm. See L<version.pod> for daily usage. This document is only useful for users -writing a subclass of version.pm or interested in the gory details. +interested in the gory details. -=head1 What IS a version +=head1 WHAT IS A VERSION? For the purposes of this module, a version "number" is a sequence of -positive integer values separated by one or more decimal points and -optionally a single underscore. This corresponds to what Perl itself -uses for a version, as well as extending the "version as number" that +positive integer values separated by one or more decimal points and +optionally a single underscore. This corresponds to what Perl itself +uses for a version, as well as extending the "version as number" that is discussed in the various editions of the Camel book. There are actually two distinct kinds of version objects: =over 4 -=item * Decimal Versions +=item Decimal Versions Any version which "looks like a number", see L<Decimal Versions>. This also includes versions with a single decimal point and a single embedded -underscore, see L<Decimal Alpha Versions>, even though these must be quoted +underscore, see L<Alpha Versions>, even though these must be quoted to preserve the underscore formatting. -=item * Dotted-Decimal Versions +=item Dotted-Decimal Versions Also referred to as "Dotted-Integer", these contains more than one decimal point and may have an optional embedded underscore, see L<Dotted-Decimal @@ -39,7 +39,7 @@ A leading 'v' character is now required and will warn if it missing. =back Both of these methods will produce similar version objects, in that -the default stringification will yield the version L<Normal Form> only +the default stringification will yield the version L<Normal Form> only if required: $v = version->new(1.002); # 1.002, but compares like 1.2.0 @@ -63,7 +63,7 @@ to the right of the decimal place) that contains less than three digits will have trailing zeros added to make up the difference, but only for purposes of comparison with other version objects. For example: - # Prints Equivalent to + # Prints Equivalent to $v = version->new( 1.2); # 1.2 v1.200.0 $v = version->new( 1.02); # 1.02 v1.20.0 $v = version->new( 1.002); # 1.002 v1.2.0 @@ -71,14 +71,14 @@ purposes of comparison with other version objects. For example: $v = version->new( 1.00203); # 1.00203 v1.2.30 $v = version->new( 1.002003); # 1.002003 v1.2.3 -All of the preceding examples are true whether or not the input value is -quoted. The important feature is that the input value contains only a -single decimal. See also L<Alpha Versions> for how to handle +All of the preceding examples are true whether or not the input value is +quoted. The important feature is that the input value contains only a +single decimal. See also L<Alpha Versions>. -IMPORTANT NOTE: As shown above, if your Decimal version contains more -than 3 significant digits after the decimal place, it will be split on -each multiple of 3, so 1.0003 is equivalent to v1.0.300, due to the need -to remain compatible with Perl's own 5.005_03 == 5.5.30 interpretation. +IMPORTANT NOTE: As shown above, if your Decimal version contains more +than 3 significant digits after the decimal place, it will be split on +each multiple of 3, so 1.0003 is equivalent to v1.0.300, due to the need +to remain compatible with Perl's own 5.005_03 == 5.5.30 interpretation. Any trailing zeros are ignored for mathematical comparison purposes. =head2 Dotted-Decimal Versions @@ -86,7 +86,7 @@ Any trailing zeros are ignored for mathematical comparison purposes. These are the newest form of versions, and correspond to Perl's own version style beginning with 5.6.0. Starting with Perl 5.10.0, and most likely Perl 6, this is likely to be the preferred form. This -method normally requires that the input parameter be quoted, although +method normally requires that the input parameter be quoted, although Perl's after 5.8.1 can use v-strings as a special form of quoting, but this is highly discouraged. @@ -102,42 +102,210 @@ a single decimal point, e.g.: In general, Dotted-Decimal Versions permit the greatest amount of freedom to specify a version, whereas Decimal Versions enforce a certain -uniformity. See also L<New Operator> for an additional method of -initializing version objects. +uniformity. -Just like L<Decimal Versions>, Dotted-Decimal Versions can be used as +Just like L<Decimal Versions>, Dotted-Decimal Versions can be used as L<Alpha Versions>. -=head2 Decimal Alpha Versions +=head2 Alpha Versions -The one time that a Decimal version must be quoted is when a alpha form is -used with an otherwise Decimal version (i.e. a single decimal point). This -is commonly used for CPAN releases, where CPAN or CPANPLUS will ignore alpha -versions for automatic updating purposes. Since some developers have used -only two significant decimal places for their non-alpha releases, the -version object will automatically take that into account if the initializer -is quoted. For example Module::Example was released to CPAN with the -following sequence of $VERSION's: +For module authors using CPAN, the convention has been to note unstable +releases with an underscore in the version string. (See L<CPAN>.) version.pm +follows this convention and alpha releases will test as being newer than the +more recent stable release, and less than the next stable release. Only the +last element may be separated by an underscore: - # $VERSION Stringified - 0.01 0.01 - 0.02 0.02 - 0.02_01 0.02_01 - 0.02_02 0.02_02 - 0.03 0.03 - etc. + # Declaring + use version 0.77; our $VERSION = version->declare("v1.2_3"); -The stringified form of Decimal versions will always be the same string -that was used to initialize the version object. + # Parsing + $v1 = version->parse("v1.2_3"); + $v1 = version->parse("1.002_003"); -=head1 High level design +Note that you B<must> quote the version when writing an alpha Decimal version. +The stringified form of Decimal versions will always be the same string that +was used to initialize the version object. -=head2 version objects +=head2 Regular Expressions for Version Parsing -version.pm provides an overloaded version object that is designed to both +A formalized definition of the legal forms for version strings is +included in the main F<version.pm> file. Primitives are included for +common elements, although they are scoped to the file so they are useful +for reference purposes only. There are two publicly accessible scalars +that can be used in other code (not exported): + +=over 4 + +=item C<$version::LAX> + +This regexp covers all of the legal forms allowed under the current +version string parser. This is not to say that all of these forms +are recommended, and some of them can only be used when quoted. + +For dotted decimals: + + v1.2 + 1.2345.6 + v1.23_4 + +The leading 'v' is optional if two or more decimals appear. If only +a single decimal is included, then the leading 'v' is required to +trigger the dotted-decimal parsing. A leading zero is permitted, +though not recommended except when quoted, because of the risk that +Perl will treat the number as octal. A trailing underscore plus one +or more digits denotes an alpha or development release (and must be +quoted to be parsed properly). + +For decimal versions: + + 1 + 1.2345 + 1.2345_01 + +an integer portion, an optional decimal point, and optionally one or +more digits to the right of the decimal are all required. A trailing +underscore is permitted and a leading zero is permitted. Just like +the lax dotted-decimal version, quoting the values is required for +alpha/development forms to be parsed correctly. + +=item C<$version::STRICT> + +This regexp covers a much more limited set of formats and constitutes +the best practices for initializing version objects. Whether you choose +to employ decimal or dotted-decimal for is a personal preference however. + +=over 4 + +=item v1.234.5 + +For dotted-decimal versions, a leading 'v' is required, with three or +more sub-versions of no more than three digits. A leading 0 (zero) +before the first sub-version (in the above example, '1') is also +prohibited. + +=item 2.3456 + +For decimal versions, an integer portion (no leading 0), a decimal point, +and one or more digits to the right of the decimal are all required. + +=back + +=back + +Both of the provided scalars are already compiled as regular expressions +and do not contain either anchors or implicit groupings, so they can be +included in your own regular expressions freely. For example, consider +the following code: + + ($pkg, $ver) =~ / + ^[ \t]* + use [ \t]+($PKGNAME) + (?:[ \t]+($version::STRICT))? + [ \t]*; + /x; + +This would match a line of the form: + + use Foo::Bar::Baz v1.2.3; # legal only in Perl 5.8.1+ + +where C<$PKGNAME> is another regular expression that defines the legal +forms for package names. + +=head1 IMPLEMENTATION DETAILS + +=head2 Equivalence between Decimal and Dotted-Decimal Versions + +When Perl 5.6.0 was released, the decision was made to provide a +transformation between the old-style decimal versions and new-style +dotted-decimal versions: + + 5.6.0 == 5.006000 + 5.005_04 == 5.5.40 + +The floating point number is taken and split first on the single decimal +place, then each group of three digits to the right of the decimal makes up +the next digit, and so on until the number of significant digits is exhausted, +B<plus> enough trailing zeros to reach the next multiple of three. + +This was the method that version.pm adopted as well. Some examples may be +helpful: + + equivalent + decimal zero-padded dotted-decimal + ------- ----------- -------------- + 1.2 1.200 v1.200.0 + 1.02 1.020 v1.20.0 + 1.002 1.002 v1.2.0 + 1.0023 1.002300 v1.2.300 + 1.00203 1.002030 v1.2.30 + 1.002003 1.002003 v1.2.3 + +=head2 Quoting Rules + +Because of the nature of the Perl parsing and tokenizing routines, +certain initialization values B<must> be quoted in order to correctly +parse as the intended version, especially when using the L<declare> or +L<qv> methods. While you do not have to quote decimal numbers when +creating version objects, it is always safe to quote B<all> initial values +when using version.pm methods, as this will ensure that what you type is +what is used. + +Additionally, if you quote your initializer, then the quoted value that goes +B<in> will be be exactly what comes B<out> when your $VERSION is printed +(stringified). If you do not quote your value, Perl's normal numeric handling +comes into play and you may not get back what you were expecting. + +If you use a mathematic formula that resolves to a floating point number, +you are dependent on Perl's conversion routines to yield the version you +expect. You are pretty safe by dividing by a power of 10, for example, +but other operations are not likely to be what you intend. For example: + + $VERSION = version->new((qw$Revision: 1.4)[1]/10); + print $VERSION; # yields 0.14 + $V2 = version->new(100/9); # Integer overflow in decimal number + print $V2; # yields something like 11.111.111.100 + +Perl 5.8.1 and beyond are able to automatically quote v-strings but +that is not possible in earlier versions of Perl. In other words: + + $version = version->new("v2.5.4"); # legal in all versions of Perl + $newvers = version->new(v2.5.4); # legal only in Perl >= 5.8.1 + +=head2 What about v-strings? + +There are two ways to enter v-strings: a bare number with two or more +decimal points, or a bare number with one or more decimal points and a +leading 'v' character (also bare). For example: + + $vs1 = 1.2.3; # encoded as \1\2\3 + $vs2 = v1.2; # encoded as \1\2 + +However, the use of bare v-strings to initialize version objects is +B<strongly> discouraged in all circumstances. Also, bare +v-strings are not completely supported in any version of Perl prior to +5.8.1. + +If you insist on using bare v-strings with Perl > 5.6.0, be aware of the +following limitations: + +1) For Perl releases 5.6.0 through 5.8.0, the v-string code merely guesses, +based on some characteristics of v-strings. You B<must> use a three part +version, e.g. 1.2.3 or v1.2.3 in order for this heuristic to be successful. + +2) For Perl releases 5.8.1 and later, v-strings have changed in the Perl +core to be magical, which means that the version.pm code can automatically +determine whether the v-string encoding was used. + +3) In all cases, a version created using v-strings will have a stringified +form that has a leading 'v' character, for the simple reason that sometimes +it is impossible to tell whether one was present initially. + +=head2 Version Object Internals + +version.pm provides an overloaded version object that is designed to both encapsulate the author's intended $VERSION assignment as well as make it completely natural to use those objects as if they were numbers (e.g. for -comparisons). To do this, a version object contains both the original +comparisons). To do this, a version object contains both the original representation as typed by the author, as well as a parsed representation to ease comparisons. Version objects employ L<overload> methods to simplify code that needs to compare, print, etc the objects. @@ -222,7 +390,7 @@ For example: IMPORTANT NOTE: This may mean that code which searches for a specific string (to determine whether a given module is available) may need to be changed. It is always better to use the built-in comparison implicit in -C<use> or C<require>, rather than manually poking at C<class->VERSION> +C<use> or C<require>, rather than manually poking at C<< class->VERSION >> and then doing a comparison yourself. The replacement UNIVERSAL::VERSION, when used as a function, like this: @@ -232,7 +400,7 @@ The replacement UNIVERSAL::VERSION, when used as a function, like this: will also exclusively return the stringified form. See L<Stringification> for more details. -=head1 Usage question +=head1 USAGE DETAILS =head2 Using modules that use version.pm @@ -270,8 +438,7 @@ With Perl >= 5.6.2, you can also use a line like this: use Example 1.2.3; and it will again work (i.e. give the error message as above), even with -releases of Perl which do not normally support v-strings (see L<What about -v-strings> below). This has to do with that fact that C<use> only checks +releases of Perl which do not normally support v-strings (see L<version/What about v-strings> below). This has to do with that fact that C<use> only checks to see if the second term I<looks like a number> and passes that to the replacement L<UNIVERSAL::VERSION>. This is not true in Perl 5.005_04, however, so you are B<strongly encouraged> to always use a Decimal version @@ -282,21 +449,15 @@ version. =head2 Object Methods -Overloading has been used with version objects to provide a natural -interface for their use. All mathematical operations are forbidden, -since they don't make any sense for base version objects. Consequently, -there is no overloaded numification available. If you want to use a -version object in a Decimal context for some reason, see the L<numify> -object method. - =over 4 -=item * New Operator +=item new() -Like all OO interfaces, the new() operator is used to initialize -version objects. One way to increment versions when programming is to -use the CVS variable $Revision, which is automatically incremented by -CVS every time the file is committed to the repository. +Like many OO interfaces, the new() method is used to initialize version +objects. If two arguments are passed to C<new()>, the B<second> one will be +used as if it were prefixed with "v". This is to support historical use of the +C<qw> operator with the CVS variable $Revision, which is automatically +incremented by CVS every time the file is committed to the repository. In order to facilitate this feature, the following code can be employed: @@ -312,7 +473,7 @@ In other words, the version will be automatically parsed out of the string, and it will be quoted to preserve the meaning CVS normally carries for versions. The CVS $Revision$ increments differently from Decimal versions (i.e. 1.10 follows 1.9), so it must be handled as if -it were a L<Dotted-Decimal Version>. +it were a Dotted-Decimal Version. A new version object can be created as a copy of an existing version object, either as a class method: @@ -337,7 +498,7 @@ example case, $v2 will be an empty object of the same type as $v1. =over 4 -=item * qv() +=item qv() An alternate way to create a new version object is through the exported qv() sub. This is not strictly like other q? operators (like qq, qw), @@ -348,7 +509,7 @@ point interpretation. For example: $v1 = qv(1.2); # v1.2.0 $v2 = qv("1.2"); # also v1.2.0 -As you can see, either a bare number or a quoted string can usually +As you can see, either a bare number or a quoted string can usually be used interchangably, except in the case of a trailing zero, which must be quoted to be converted properly. For this reason, it is strongly recommended that all initializers to qv() be quoted strings instead of @@ -364,33 +525,32 @@ or just require version, like this: require version; Both methods will prevent the import() method from firing and exporting the -C<qv()> sub. This is true of subclasses of version as well, see -L<SUBCLASSING> for details. +C<qv()> sub. =back For the subsequent examples, the following three objects will be used: - $ver = version->new("1.2.3.4"); # see "Quoting" below - $alpha = version->new("1.2.3_4"); # see "Alpha versions" below - $nver = version->new(1.002); # see "Decimal Versions" above + $ver = version->new("1.2.3.4"); # see "Quoting Rules" + $alpha = version->new("1.2.3_4"); # see "Alpha Versions" + $nver = version->new(1.002); # see "Decimal Versions" =over 4 -=item * Normal Form +=item Normal Form For any version object which is initialized with multiple decimal places (either quoted or if possible v-string), or initialized using -the L<qv()> operator, the stringified representation is returned in +the L<qv>() operator, the stringified representation is returned in a normalized or reduced form (no extraneous zeros), and with a leading 'v': print $ver->normal; # prints as v1.2.3.4 print $ver->stringify; # ditto print $ver; # ditto print $nver->normal; # prints as v1.2.0 - print $nver->stringify; # prints as 1.002, see "Stringification" + print $nver->stringify; # prints as 1.002, see "Stringification" -In order to preserve the meaning of the processed version, the +In order to preserve the meaning of the processed version, the normalized representation will always contain at least three sub terms. In other words, the following is guaranteed to always be true: @@ -402,10 +562,10 @@ In other words, the following is guaranteed to always be true: =over 4 -=item * Numification +=item Numification Although all mathematical operations on version objects are forbidden -by default, it is possible to retrieve a number which corresponds +by default, it is possible to retrieve a number which corresponds to the version object through the use of the $obj->numify method. For formatting purposes, when displaying a number which corresponds a version object, all sub versions are assumed to have @@ -421,7 +581,7 @@ trailing zeros to preserve the correct version value. =over 4 -=item * Stringification +=item Stringification The default stringification for version objects returns exactly the same string as was used to create it, whether you used C<new()> or C<qv()>, @@ -438,29 +598,29 @@ For example: version->new("v1.2") v1.2 qv("1.2.3") 1.2.3 qv("v1.3.5") v1.3.5 - qv("1.2") v1.2 ### exceptional case + qv("1.2") v1.2 ### exceptional case See also L<UNIVERSAL::VERSION>, as this also returns the stringified form when used as a class method. IMPORTANT NOTE: There is one exceptional cases shown in the above table where the "initializer" is not stringwise equivalent to the stringified -representation. If you use the C<qv()> operator on a version without a +representation. If you use the C<qv>() operator on a version without a leading 'v' B<and> with only a single decimal place, the stringified output -will have a leading 'v', to preserve the sense. See the L<qv()> operator +will have a leading 'v', to preserve the sense. See the L<qv>() operator for more details. IMPORTANT NOTE 2: Attempting to bypass the normal stringification rules by -manually applying L<numify()> and L<normal()> will sometimes yield +manually applying L<numify>() and L<normal>() will sometimes yield surprising results: print version->new(version->new("v1.0")->numify)->normal; # v1.0.0 -The reason for this is that the L<numify()> operator will turn "v1.0" +The reason for this is that the L<numify>() operator will turn "v1.0" into the equivalent string "1.000000". Forcing the outer version object -to L<normal()> form will display the mathematically equivalent "v1.0.0". +to L<normal>() form will display the mathematically equivalent "v1.0.0". -As the example in L<new()> shows, you can always create a copy of an +As the example in L<new>() shows, you can always create a copy of an existing version object with the same value by the very compact: $v2 = $v1->new($v1); @@ -472,7 +632,7 @@ down to the same internal representation as well as stringification. =over 4 -=item * Comparison operators +=item Comparison operators Both C<cmp> and C<E<lt>=E<gt>> operators perform the same comparison between terms (upgrading to a version object automatically). Perl automatically @@ -493,7 +653,7 @@ For example, the following relations hold: It is probably best to chose either the Decimal notation or the string notation and stick with it, to reduce confusion. Perl6 version objects -B<may> only support Decimal comparisons. See also L<Quoting>. +B<may> only support Decimal comparisons. See also L<Quoting Rules>. WARNING: Comparing version with unequal numbers of decimal points (whether explicitly or implicitly initialized), may yield unexpected results at @@ -509,7 +669,7 @@ L<Dotted-Decimal Versions> with multiple decimal points. =over 4 -=item * Logical Operators +=item Logical Operators If you need to test whether a version object has been initialized, you can simply test it directly: @@ -517,7 +677,7 @@ has been initialized, you can simply test it directly: $vobj = version->new($something); if ( $vobj ) # true only if $something was non-blank -You can also test whether a version object is an L<Alpha version>, for +You can also test whether a version object is an alpha version, for example to prevent the use of some feature not present in the main release: @@ -527,76 +687,6 @@ release: =back -=head2 Quoting - -Because of the nature of the Perl parsing and tokenizing routines, -certain initialization values B<must> be quoted in order to correctly -parse as the intended version, especially when using the L<qv()> operator. -In all cases, a floating point number passed to version->new() will be -identically converted whether or not the value itself is quoted. This is -not true for L<qv()>, however, when trailing zeros would be stripped on -an unquoted input, which would result in a very different version object. - -In addition, in order to be compatible with earlier Perl version styles, -any use of versions of the form 5.006001 will be translated as v5.6.1. -In other words, a version with a single decimal point will be parsed as -implicitly having three digits between subversions, but only for internal -comparison purposes. - -The complicating factor is that in bare numbers (i.e. unquoted), the -underscore is a legal Decimal character and is automatically stripped -by the Perl tokenizer before the version code is called. However, if -a number containing one or more decimals and an underscore is quoted, i.e. -not bare, that is considered a L<Alpha Version> and the underscore is -significant. - -If you use a mathematic formula that resolves to a floating point number, -you are dependent on Perl's conversion routines to yield the version you -expect. You are pretty safe by dividing by a power of 10, for example, -but other operations are not likely to be what you intend. For example: - - $VERSION = version->new((qw$Revision: 1.4)[1]/10); - print $VERSION; # yields 0.14 - $V2 = version->new(100/9); # Integer overflow in decimal number - print $V2; # yields something like 11.111.111.100 - -Perl 5.8.1 and beyond will be able to automatically quote v-strings but -that is not possible in earlier versions of Perl. In other words: - - $version = version->new("v2.5.4"); # legal in all versions of Perl - $newvers = version->new(v2.5.4); # legal only in Perl >= 5.8.1 - -=head1 SUBCLASSING - -This module is specifically designed and tested to be easily subclassed. -In practice, you only need to override the methods you want to change, but -you have to take some care when overriding new() (since that is where all -of the parsing takes place). For example, this is a perfect acceptable -derived class: - - package myversion; - use base version; - sub new { - my($self,$n)=@_; - my $obj; - # perform any special input handling here - $obj = $self->SUPER::new($n); - # and/or add additional hash elements here - return $obj; - } - -See also L<version::AlphaBeta> on CPAN for an alternate representation of -version strings. - -B<NOTE:> Although the L<qv> operator is not a true class method, but rather a -function exported into the caller's namespace, a subclass of version will -inherit an import() function which will perform the correct magic on behalf -of the subclass. - -=head1 EXPORT - -qv - Dotted-Decimal Version initialization operator - =head1 AUTHOR John Peacock E<lt>jpeacock@cpan.orgE<gt> |