use Test::More 'tests' => 25; use Scalar::Util qw( reftype blessed ); ok( 'foo' =~ //, '"foo" matches empty expression' ); # a real regexp, not blessed, works like this my $rx = qr/f(oo)/; is( ref $rx, 'Regexp', 'ref $rx eq "Regexp"' ); is( blessed $rx, 'Regexp', '$rx is blessed as "Regexp"' ); is( reftype $rx, 'SCALAR', 'reftype $rx eq "SCALAR"' ); ok( ! defined $$rx, '$$rx is not defined' ); ok( 'foo' =~ $rx, '$rx matches "foo"' ); is( $&, 'foo', 'matched text is "foo"' ); is( $1, 'oo', 'first capture is "oo"' ); # a blessed regexp works the same way, # but what other evidence can tell me it's a regexp? bless $rx, 'NotRegexp'; is( ref $rx, 'NotRegexp', 'ref $rx eq "NotRegexp"' ); is( blessed $rx, 'NotRegexp', '$rx is blessed as "NotRegexp"' ); is( reftype $rx, 'SCALAR', 'reftype $rx eq "SCALAR"' ); ok( ! defined $$rx, '$$rx is not defined' ); ok( 'foo' =~ $rx, '$rx matches "foo"' ); is( $&, 'foo', 'matched text is "foo"' ); is( $1, 'oo', 'first capture is "oo"' ); # this looks just like the blessed regexp, but it doesn't function my $o; my $notrx = \$o; bless $notrx, 'NotRegexp'; is( ref $notrx, 'NotRegexp', 'ref $notrx eq "NotRegexp"' ); is( blessed $notrx, 'NotRegexp', '$notrx is blessed as "NotRegexp"' ); is( reftype $notrx, 'SCALAR', 'reftype $notrx eq "SCALAR"' ); ok( ! defined $$notrx, '$$notrx is not defined' ); ok( !('foo' =~ $notrx), '$notrx does not match "foo"' ); # this looks just like the real regexp, but it doesn't function bless $notrx, 'Regexp'; is( ref $notrx, 'Regexp', 'ref $notrx eq "Regexp"' ); is( blessed $notrx, 'Regexp', '$notrx is blessed as "Regexp"' ); is( reftype $notrx, 'SCALAR', 'reftype $notrx eq "SCALAR"' ); ok( ! defined $$notrx, '$$notrx is not defined' ); ok( !('foo' =~ $notrx), '$notrx does not match "foo"' );