I'm a month late, but here goes:

* Robert Rothenberg <[EMAIL PROTECTED]> [2004-11-14 15:21]:
> sub is_string_like {
> 
>   return 1,
>     unless (defined $_[0] && ref $_[0]);
> 
>   # We don't evaluate whether the "." and ".=" operators are
>   # supported, since for many applications that use strings, the
>   # comparison operators are the most important.
> 
>   eval {
>     ("$_[0]")
>       && (($_[0] cmp $_[0])==0)
>       && ($_[0] eq $_[0])
>       && (!($_[0] ne $_[0]))
>       && (!($_[0] le $_[0]))
>       && (!($_[0] ge $_[0]))
>       && (!($_[0] lt $_[0]))
>       && (!($_[0] gt $_[0]))
>   } and return 1;
> 
>   # Testing for behavior related to copy constructors is another issue
>   # to be determined....
> 
>   return;
> }

That can be condensed to

    use overload;
    sub is_stringish {
        return 1 if not ( defined $_[ 0 ] and ref $_[ 0 ] );
        return if not overload::Overloaded( $_[ 0 ] );
        return (
            overload::Method( $_[ 0 ], '""' )
            and overload::Method( $_[ 0 ], 'cmp' )
            # etc etc
            and 1 # convert to bool
        );
    }

Regards,
-- 
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hacker;

Reply via email to