In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/47b13905e23c2a72acdde8bb4669e25e5eaefec4?hp=c89e1b5ce75f6c47bfc6ebb8dc0602bd7ef88427>
- Log ----------------------------------------------------------------- commit 47b13905e23c2a72acdde8bb4669e25e5eaefec4 Author: Zsbán Ambrus <amb...@math.bme.hu> Date: Mon Aug 30 19:24:18 2010 +0200 add more tests to lib/mauve.t so it tests also that mauve::reftype can return "LVALUE" M AUTHORS M lib/mauve.t commit cfe9162d0d593cd12a979c73df82c7509b324343 Author: Yves Orton <demer...@gmail.com> Date: Mon Aug 30 19:05:27 2010 +0200 use more efficient sv_reftype_len() interface M pp.c ----------------------------------------------------------------------- Summary of changes: AUTHORS | 1 + lib/mauve.t | 57 ++++++++++++++++++++++++++++++++++++++++----------------- pp.c | 5 +++-- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/AUTHORS b/AUTHORS index ab0d3db..e7e3fb2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1068,5 +1068,6 @@ Yuval Kogman <nothingm...@woobling.org> Yves Orton <demer...@gmail.com> Zachary Miller <zcmil...@simon.er.usgs.gov> Zefram <zef...@fysh.org> +Zsbán Ambrus <amb...@math.bme.hu> Zbynek Vyskovsky <k...@centrum.cz> Ævar Arnfjörð Bjarmason <a...@cpan.org> diff --git a/lib/mauve.t b/lib/mauve.t index 9a26491..c956c07 100644 --- a/lib/mauve.t +++ b/lib/mauve.t @@ -1,6 +1,6 @@ #!./perl -use Test::More tests => 32 + 29 + 12 + 22; +use Test::More tests => 32 + 60 + 12 + 22; use mauve qw(refaddr reftype blessed weaken isweak); use vars qw($t $y $x *F $v $r $never_blessed); @@ -57,32 +57,55 @@ foreach $r ({}, \$t, [], \*F, sub {}) { } { - my $RE = $] < 5.011 ? 'SCALAR' : 'REGEXP'; + my $HAVE_RE = 5.011 <= $]; + my $RE = $HAVE_RE ? 'REGEXP' : 'SCALAR'; + my($m,@m,%m); + format STDOUT = # do not indent the lone dot in next line +. @test = ( - [ !1, 1, 'number' ], - [ !1, 'A', 'string' ], - [ HASH => {}, 'HASH ref' ], - [ ARRAY => [], 'ARRAY ref' ], - [ SCALAR => \$t, 'SCALAR ref' ], - [ REF => \(\$t), 'REF ref' ], - [ GLOB => \*F, 'tied GLOB ref' ], - [ GLOB => gensym, 'GLOB ref' ], - [ CODE => sub {}, 'CODE ref' ], - [ IO => *STDIN{IO},'IO ref' ], - [ $RE => qr/x/, 'REGEEXP' ], + [ 0, !1, 1, 'number' ], + [ 0, !1, 'A', 'string' ], + [ 0, !1, *::t, 'glob' ], + [ 1, HASH => {}, 'HASH ref' ], + [ 1, HASH => \%::t, 'HASH ref' ], + [ 1, HASH => \%m, 'HASH ref' ], + [ 1, ARRAY => [], 'ARRAY ref' ], + [ 1, ARRAY => \@::t, 'ARRAY ref' ], + [ 1, ARRAY => \...@m, 'ARRAY ref' ], + [ 0, SCALAR => \1, 'SCALAR ref' ], + [ 1, SCALAR => \$t, 'SCALAR ref' ], + [ 1, SCALAR => \$m, 'SCALAR ref' ], + [ 1, REF => \(\$t), 'REF ref' ], + [ 1, REF => \[], 'REF ref' ], + [ 1, LVALUE => \substr("",0), 'LVALUE ref' ], + [ 0, VSTRING => \v1.0.0, 'VSTRING ref' ], + [ 1, VSTRING => \(my $v = v1.0.0), 'VSTRING ref' ], + [ 1, GLOB => \*F, 'tied GLOB ref' ], + [ 1, GLOB => gensym, 'GLOB ref' ], + [ 1, CODE => sub {}, 'CODE ref' ], + [ 1, IO => *STDIN{IO}, 'IO ref' ], + [ 1, FORMAT => *STDOUT{FORMAT}, 'FORMAT ref' ], + [ 1, $RE => qr/x/, 'REGEXP' ], + [ 0, !1, ${qr//}, 'derefed regex' ], ); foreach $test (@test) { - my($type,$what, $n) = @$test; + my($writable,$type,$what, $n) = @$test; + + SKIP: { + if ($n =~ /derefed regex/i && !$HAVE_RE) { + skip "regexes are not scalar references in perl < 5.011", 1; + } is( reftype($what), $type, "reftype: $n"); - next unless ref($what); + next unless $writable; bless $what, "ABC"; - is( reftype($what), $type, "reftype: $n"); + is( reftype($what), $type, "reftype: blessed $n"); bless $what, "0"; - is( reftype($what), $type, "reftype: $n"); + is( reftype($what), $type, "reftype: blessed to false $n"); + } } } { diff --git a/pp.c b/pp.c index fcb7ff2..31614ed 100644 --- a/pp.c +++ b/pp.c @@ -559,6 +559,7 @@ PP(pp_ref) dVAR; dSP; dTARGET; const char *pv; SV * const sv = POPs; + STRLEN len; if (sv) SvGETMAGIC(sv); @@ -566,8 +567,8 @@ PP(pp_ref) if (!sv || !SvROK(sv)) RETPUSHNO; - pv = sv_reftype(SvRV(sv),TRUE); - PUSHp(pv, strlen(pv)); + pv = sv_reftype_len(SvRV(sv),TRUE,&len); + PUSHp(pv, len); RETURN; } -- Perl5 Master Repository