goto &ok;
}
-my %binops;
-BEGIN {
- %binops = (
- 'or' => 'or',
- 'and' => 'and',
- 'xor' => 'xor',
-
- '||' => 'hor',
- '&&' => 'hand',
-
- 'lt' => 'lt',
- 'le' => 'le',
- 'gt' => 'gt',
- 'ge' => 'ge',
- 'eq' => 'eq',
- 'ne' => 'ne',
- 'cmp' => 'cmp',
-
- '<' => 'nlt',
- '<=' => 'nle',
- '>' => 'ngt',
- '>=' => 'nge',
- '==' => 'neq',
- '!=' => 'nne',
- '<=>' => 'ncmp',
-
- '=~' => 'like',
- '!~' => 'unlike',
- '~~' => 'smartmatch',
- );
-
- for my $op (sort keys %binops) {
- my $name = $binops{$op};
- local $@;
- eval <<"IS_BINOP";
-sub is_$name (\$\$;\$) {
- my (\$got, \$expected, \$desc) = \@_;
- \@_ = ((\$got $op \$expected), \$desc);
- goto &ok;
-}
-IS_BINOP
- die $@ if $@;
- }
-}
-
sub is ($$;$) {
my ($got, $expected, $desc) = @_;
no warnings 'uninitialized';
goto &ok;
}
+my %binops = (
+ 'or' => 'or',
+ 'and' => 'and',
+ 'xor' => 'xor',
+
+ '||' => 'hor',
+ '&&' => 'hand',
+
+ 'lt' => 'lt',
+ 'le' => 'le',
+ 'gt' => 'gt',
+ 'ge' => 'ge',
+ 'eq' => 'eq',
+ 'ne' => 'ne',
+ 'cmp' => 'cmp',
+
+ '<' => 'nlt',
+ '<=' => 'nle',
+ '>' => 'ngt',
+ '>=' => 'nge',
+ '==' => 'neq',
+ '!=' => 'nne',
+ '<=>' => 'ncmp',
+
+ '=~' => 'like',
+ '!~' => 'unlike',
+ '~~' => 'smartmatch',
+);
+
+my %binop_handlers;
+
+sub _create_binop_handler {
+ my ($op) = @_;
+ my $name = $binops{$op};
+ croak("Operator $op not supported") unless defined $name;
+ {
+ local $@;
+ eval <<"IS_BINOP";
+sub is_$name (\$\$;\$) {
+ my (\$got, \$expected, \$desc) = \@_;
+ \@_ = ((\$got $op \$expected), \$desc);
+ goto &ok;
+}
+IS_BINOP
+ die $@ if $@;
+ }
+ $binop_handlers{$op} = do {
+ no strict 'refs';
+ \&{__PACKAGE__."::is_$name"};
+ }
+}
+
{
no warnings 'once';
- *like = \&is_like;
- *unlike = \&is_unlike;
+ *like = _create_binop_handler('=~');
+ *unlike = _create_binop_handler('!~');
}
sub cmp_ok ($$$;$) {
my ($got, $op, $expected, $desc) = @_;
- my $name = $binops{$op};
- croak("Operator $op not supported") unless defined $name;
+ my $handler = $binop_handlers{$op};
+ unless ($handler) {
+ local $Test::More::Level = ($Test::More::Level || 0) + 1;
+ $handler = _create_binop_handler($op);
+ }
@_ = ($got, $expected, $desc);
- no strict 'refs';
- goto &{__PACKAGE__."::is_$name"};
+ goto $handler;
}
sub _diag_fh {