{
    "mode": "perldoc",
    "parameter": "UNIVERSAL",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL/json",
    "generated": "2026-06-14T05:55:21Z",
    "synopsis": "$isio    = $fd->isa(\"IO::Handle\");\n$isio    = Class->isa(\"IO::Handle\");\n$doeslog = $obj->DOES(\"Logger\");\n$doeslog = Class->DOES(\"Logger\");\n$sub      = $obj->can(\"print\");\n$sub      = Class->can(\"print\");\n$sub      = eval { $ref->can(\"fandango\") };\n$ver      = $obj->VERSION;\n# but never do this!\n$isio    = UNIVERSAL::isa($fd, \"IO::Handle\");\n$sub      = UNIVERSAL::can($obj, \"print\");",
    "sections": {
        "NAME": {
            "content": "UNIVERSAL - base class for ALL classes (blessed references)\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "$isio    = $fd->isa(\"IO::Handle\");\n$isio    = Class->isa(\"IO::Handle\");\n\n$doeslog = $obj->DOES(\"Logger\");\n$doeslog = Class->DOES(\"Logger\");\n\n$sub      = $obj->can(\"print\");\n$sub      = Class->can(\"print\");\n\n$sub      = eval { $ref->can(\"fandango\") };\n$ver      = $obj->VERSION;\n\n# but never do this!\n$isio    = UNIVERSAL::isa($fd, \"IO::Handle\");\n$sub      = UNIVERSAL::can($obj, \"print\");\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"UNIVERSAL\" is the base class from which all blessed references inherit. See perlobj.\n\n\"UNIVERSAL\" provides the following methods:\n\n\"$obj->isa( TYPE )\"\n\"CLASS->isa( TYPE )\"\n\"eval { VAL->isa( TYPE ) }\"\nWhere\n\n\"TYPE\"\nis a package name\n\n$obj\nis a blessed reference or a package name\n\n\"CLASS\"\nis a package name\n\n\"VAL\"\nis any of the above or an unblessed reference\n\nWhen used as an instance or class method (\"$obj->isa( TYPE )\"), \"isa\" returns *true* if $obj\nis blessed into package \"TYPE\" or inherits from package \"TYPE\".\n\nWhen used as a class method (\"CLASS->isa( TYPE )\", sometimes referred to as a static\nmethod), \"isa\" returns *true* if \"CLASS\" inherits from (or is itself) the name of the\npackage \"TYPE\" or inherits from package \"TYPE\".\n\nIf you're not sure what you have (the \"VAL\" case), wrap the method call in an \"eval\" block\nto catch the exception if \"VAL\" is undefined.\n\nIf you want to be sure that you're calling \"isa\" as a method, not a class, check the\ninvocand with \"blessed\" from Scalar::Util first:\n\nuse Scalar::Util 'blessed';\n\nif ( blessed( $obj ) && $obj->isa(\"Some::Class\") ) {\n...\n}\n\n\"$obj->DOES( ROLE )\"\n\"CLASS->DOES( ROLE )\"\n\"DOES\" checks if the object or class performs the role \"ROLE\". A role is a named group of\nspecific behavior (often methods of particular names and signatures), similar to a class,\nbut not necessarily a complete class by itself. For example, logging or serialization may be\nroles.\n\n\"DOES\" and \"isa\" are similar, in that if either is true, you know that the object or class\non which you call the method can perform specific behavior. However, \"DOES\" is different\nfrom \"isa\" in that it does not care *how* the invocand performs the operations, merely that\nit does. (\"isa\" of course mandates an inheritance relationship. Other relationships include\naggregation, delegation, and mocking.)\n\nBy default, classes in Perl only perform the \"UNIVERSAL\" role, as well as the role of all\nclasses in their inheritance. In other words, by default \"DOES\" responds identically to\n\"isa\".\n\nThere is a relationship between roles and classes, as each class implies the existence of a\nrole of the same name. There is also a relationship between inheritance and roles, in that a\nsubclass that inherits from an ancestor class implicitly performs any roles its parent\nperforms. Thus you can use \"DOES\" in place of \"isa\" safely, as it will return true in all\nplaces where \"isa\" will return true (provided that any overridden \"DOES\" *and* \"isa\" methods\nbehave appropriately).\n\n\"$obj->can( METHOD )\"\n\"CLASS->can( METHOD )\"\n\"eval { VAL->can( METHOD ) }\"\n\"can\" checks if the object or class has a method called \"METHOD\". If it does, then it\nreturns a reference to the sub. If it does not, then it returns *undef*. This includes\nmethods inherited or imported by $obj, \"CLASS\", or \"VAL\".\n\n\"can\" cannot know whether an object will be able to provide a method through AUTOLOAD\n(unless the object's class has overridden \"can\" appropriately), so a return value of *undef*\ndoes not necessarily mean the object will not be able to handle the method call. To get\naround this some module authors use a forward declaration (see perlsub) for methods they\nwill handle via AUTOLOAD. For such 'dummy' subs, \"can\" will still return a code reference,\nwhich, when called, will fall through to the AUTOLOAD. If no suitable AUTOLOAD is provided,\ncalling the coderef will cause an error.\n\nYou may call \"can\" as a class (static) method or an object method.\n\nAgain, the same rule about having a valid invocand applies -- use an \"eval\" block or\n\"blessed\" if you need to be extra paranoid.\n\n\"VERSION ( [ REQUIRE ] )\"\n\"VERSION\" will return the value of the variable $VERSION in the package the object is\nblessed into. If \"REQUIRE\" is given then it will do a comparison and die if the package\nversion is not greater than or equal to \"REQUIRE\", or if either $VERSION or \"REQUIRE\" is not\na \"lax\" version number (as defined by the version module).\n\nThe return from \"VERSION\" will actually be the stringified version object using the package\n$VERSION scalar, which is guaranteed to be equivalent but may not be precisely the contents\nof the $VERSION scalar. If you want the actual contents of $VERSION, use $CLASS::VERSION\ninstead.\n\n\"VERSION\" can be called as either a class (static) method or an object method.\n",
            "subsections": []
        },
        "WARNINGS": {
            "content": "NOTE: \"can\" directly uses Perl's internal code for method lookup, and \"isa\" uses a very similar\nmethod and cache-ing strategy. This may cause strange effects if the Perl code dynamically\nchanges @ISA in any package.\n\nYou may add other methods to the UNIVERSAL class via Perl or XS code. You do not need to \"use\nUNIVERSAL\" to make these methods available to your program (and you should not do so).\n",
            "subsections": []
        },
        "EXPORTS": {
            "content": "None.\n\nPrevious versions of this documentation suggested using \"isa\" as a function to determine the\ntype of a reference:\n\n$yes = UNIVERSAL::isa($h, \"HASH\");\n$yes = UNIVERSAL::isa(\"Foo\", \"Bar\");\n\nThe problem is that this code would *never* call an overridden \"isa\" method in any class.\nInstead, use \"reftype\" from Scalar::Util for the first case:\n\nuse Scalar::Util 'reftype';\n\n$yes = reftype( $h ) eq \"HASH\";\n\nand the method form of \"isa\" for the second:\n\n$yes = Foo->isa(\"Bar\");\n",
            "subsections": []
        }
    },
    "summary": "UNIVERSAL - base class for ALL classes (blessed references)",
    "flags": [],
    "examples": [],
    "see_also": []
}