in reply to Re: Arrgh, can() appears to work for non-object !!
in thread Arrgh, can() appears to work for non-object !!

TFT ysth,

Yes, I know both can and isa work on both classes and objects, the thing is how can fred be a class ? Shouldn't I have expected a method can not found for class fred, did you forget to load fred ? type of error ?

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^3: Arrgh, can() appears to work for non-object !!
by ysth (Canon) on Jan 07, 2009 at 11:32 UTC
    No, since nothing about a class is required. It need have no methods, @ISA, or anything else, so there's nothing missing to provoke a "forget to load" kind of error. Even the package statement isn't required, since you can declare anything using a fully qualified name if you want.
      Does that mean that it's safe to infer that perl will, if it thinks it appropriate, treat all literals/string constants as class names ?

      A user level that continues to overstate my experience :-))
        Does that mean that it's safe to infer that perl will, if it thinks it appropriate, treat all literals/string constants as class names ?
        No. It will only treat strings that start with a letter or underscore to be class names:
        $ perl -wE 'say "fred" -> can ("can")' Use of uninitialized value in say at -e line 1. $ perl -wE 'say "1fred" -> can ("can")' Can't call method "can" without a package or object reference at -e li +ne 1. $ perl -wE 'say " " -> can ("can")' Can't call method "can" without a package or object reference at -e li +ne 1. $ perl -wE 'say "f r e d" -> can ("can")' Use of uninitialized value in say at -e line 1. $
        But this "autocasting" is not surprising. Perl does that all the time. String can be numbers or regexes. Numbers can be strings. Floats can be integers, etc.

        No. That's only true for a Literal in Literal->method an only if method is in UNIVERSAL.