From: Jarkko Hietaniemi Date: Tue, 1 May 2001 19:21:41 +0000 (+0000) Subject: Update to Switch 2.02. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3961318eaa1a2f6d3cdb9971bd0f3734b30294af;p=p5sagit%2Fp5-mst-13.2.git Update to Switch 2.02. p4raw-id: //depot/perl@9937 --- diff --git a/lib/Switch.pm b/lib/Switch.pm index 1b84371..2a3093c 100644 --- a/lib/Switch.pm +++ b/lib/Switch.pm @@ -4,7 +4,7 @@ use strict; use vars qw($VERSION); use Carp; -$VERSION = '2.01'; +$VERSION = '2.02'; # LOAD FILTERING MODULE... @@ -18,10 +18,10 @@ $::_S_W_I_T_C_H = sub { croak "case statement not in switch block" }; my $offset; my $fallthrough; -my $nextlabel = 1; sub import { + $DB::single = 1; $fallthrough = grep /\bfallthrough\b/, @_; $offset = (caller)[2]+1; filter_add({}) unless @_>1 && $_[1] ne '__'; @@ -80,7 +80,7 @@ sub filter_blocks my $text = ""; component: while (pos $source < length $source) { - if ($source =~ m/(\G\s*use\s+switch\b)/gc) + if ($source =~ m/(\G\s*use\s+Switch\b)/gc) { $text .= q{use Switch 'noimport'}; next component; @@ -88,20 +88,20 @@ sub filter_blocks my @pos = Text::Balanced::_match_quotelike(\$source,qr/\s*/,1,1); if (defined $pos[0]) { - $text .= substr($source,$pos[2],$pos[18]-$pos[2]); + $text .= " " . substr($source,$pos[2],$pos[18]-$pos[2]); next component; } @pos = Text::Balanced::_match_variable(\$source,qr/\s*/); if (defined $pos[0]) { - $text .= substr($source,$pos[0],$pos[4]-$pos[0]); + $text .= " " . substr($source,$pos[0],$pos[4]-$pos[0]); next component; } if ($source =~ m/\G(\n*)(\s*)switch\b(?=\s*[(])/gc) { $text .= $1.$2.'S_W_I_T_C_H: while (1) '; - @pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\(/,qr/\)/,qr/\{/,qr/\}/,undef) + @pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\(/,qr/\)/,qr/[[{(<]/,qr/[]})>]/,undef) or do { die "Bad switch statement (problem in the parentheses?) near $Switch::file line ", line(substr($source,0,pos $source),$line), "\n"; }; @@ -454,8 +454,8 @@ Switch - A switch statement for Perl =head1 VERSION -This document describes version 2.01 of Switch, -released January 9, 2001. +This document describes version 2.02 of Switch, +released April 26, 2001. =head1 SYNOPSIS diff --git a/t/lib/switch.t b/t/lib/switch.t index 3fcd5ca..d1a8af1 100644 --- a/t/lib/switch.t +++ b/t/lib/switch.t @@ -6,16 +6,8 @@ BEGIN { use Carp; use Switch qw(__ fallthrough); -print "1..293\n"; - -my $count = 0; -sub ok($) -{ - $count++; - print "line ", (caller)[2], "; " unless $_[0]; - print "not " unless $_[0]; - print "ok $count\n"; -} +my($C,$M);sub ok{$C++;$M.=$_[0]?"ok $C\n":"not ok $C (line ".(caller)[2].")\n"} +END{print"1..$C\n$M"} # NON-case THINGS;