1#! perl 2 3{ 4 package Test::Overloaded::String; 5 6 use vars qw( $called_string_overload ); 7 8 use strict; 9 use warnings; 10 11 use overload '""' => sub { $called_string_overload++ }; 12 13 sub new { bless {}, shift } 14 15 sub foo { } 16} 17 18package main; 19 20use strict; 21use warnings; 22 23use Test::More tests => 3; 24use UNIVERSAL::can; 25 26ok( eval { Test::Overloaded::String->new->can('foo') }, 27 "->can should return true for an existing method" ); 28ok( !eval { Test::Overloaded::String->new->can('bar') }, 29 "->can should return false for a non-existent method" ); 30ok( !$Test::Overloaded::String::called_string_overload, 31 "it should not trigger the string overload on the invocant in either case" ); 32