Edit D:\app\Administrator\product\11.2.0\dbhome_1\perl\html\lib\UNIVERSAL.html
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>UNIVERSAL - base class for ALL classes</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rev="made" href="mailto:" /> </head> <body style="background-color: white"> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> UNIVERSAL - base class for ALL classes</span></strong></big> </td></tr> </table> <!-- INDEX BEGIN --> <div name="index"> <p><a name="__index__"></a></p> <ul> <li><a href="#name">NAME</a></li> <li><a href="#synopsis">SYNOPSIS</a></li> <li><a href="#description">DESCRIPTION</a></li> <li><a href="#exports">EXPORTS</a></li> </ul> <hr name="index" /> </div> <!-- INDEX END --> <p> </p> <h1><a name="name">NAME</a></h1> <p>UNIVERSAL - base class for ALL classes (blessed references)</p> <p> </p> <hr /> <h1><a name="synopsis">SYNOPSIS</a></h1> <pre> $is_io = $fd->isa("IO::Handle"); $is_io = Class->isa("IO::Handle");</pre> <pre> $does_log = $obj->DOES("Logger"); $does_log = Class->DOES("Logger");</pre> <pre> $sub = $obj->can("print"); $sub = Class->can("print");</pre> <pre> $sub = eval { $ref->can("fandango") }; $ver = $obj->VERSION;</pre> <pre> # but never do this! $is_io = UNIVERSAL::isa($fd, "IO::Handle"); $sub = UNIVERSAL::can($obj, "print");</pre> <p> </p> <hr /> <h1><a name="description">DESCRIPTION</a></h1> <p><code>UNIVERSAL</code> is the base class from which all blessed references inherit. See <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlobj.html">the perlobj manpage</a>.</p> <p><code>UNIVERSAL</code> provides the following methods:</p> <dl> <dt><strong><a name="isa" class="item"><code>$obj->isa( TYPE )</code></a></strong> <dt><strong><code>CLASS->isa( TYPE )</code></strong> <dt><strong><code>eval { VAL->isa( TYPE ) }</code></strong> <dd> <p>Where</p> </dd> <dl> <dt><strong><a name="type4" class="item"><a href="#type"><code>TYPE</code></a></a></strong> <dd> <p>is a package name</p> </dd> </li> <dt><strong><a name="_obj" class="item"><code>$obj</code></a></strong> <dd> <p>is a blessed reference or a string containing a package name</p> </dd> </li> <dt><strong><a name="class2" class="item"><a href="#class"><code>CLASS</code></a></a></strong> <dd> <p>is a package name</p> </dd> </li> <dt><strong><a name="val" class="item"><code>VAL</code></a></strong> <dd> <p>is any of the above or an unblessed reference</p> </dd> </li> </dl> <p>When used as an instance or class method (<a href="#isa"><code>$obj->isa( TYPE )</code></a>), <a href="#isa"><code>isa</code></a> returns <em>true</em> if $obj is blessed into package <a href="#type"><code>TYPE</code></a> or inherits from package <a href="#type"><code>TYPE</code></a>.</p> <p>When used as a class method (<a href="#isa"><code>CLASS->isa( TYPE )</code></a>, sometimes referred to as a static method), <a href="#isa"><code>isa</code></a> returns <em>true</em> if <a href="#class"><code>CLASS</code></a> inherits from (or is itself) the name of the package <a href="#type"><code>TYPE</code></a> or inherits from package <a href="#type"><code>TYPE</code></a>.</p> <p>If you're not sure what you have (the <a href="#val"><code>VAL</code></a> case), wrap the method call in an <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#eval"><code>eval</code></a> block to catch the exception if <a href="#val"><code>VAL</code></a> is undefined.</p> <p>If you want to be sure that you're calling <a href="#isa"><code>isa</code></a> as a method, not a class, check the invocant with <code>blessed</code> from <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Scalar/Util.html">the Scalar::Util manpage</a> first:</p> <pre> use Scalar::Util 'blessed';</pre> <pre> if ( blessed( $obj ) && $obj->isa("Some::Class") { ... }</pre> <dt><strong><a name="does" class="item"><code>$obj->DOES( ROLE )</code></a></strong> <dt><strong><code>CLASS->DOES( ROLE )</code></strong> <dd> <p><a href="#does"><code>DOES</code></a> checks if the object or class performs the role <code>ROLE</code>. A role is a named group of specific behavior (often methods of particular names and signatures), similar to a class, but not necessarily a complete class by itself. For example, logging or serialization may be roles.</p> </dd> <dd> <p><a href="#does"><code>DOES</code></a> and <a href="#isa"><code>isa</code></a> are similar, in that if either is true, you know that the object or class on which you call the method can perform specific behavior. However, <a href="#does"><code>DOES</code></a> is different from <a href="#isa"><code>isa</code></a> in that it does not care <em>how</em> the invocant performs the operations, merely that it does. (<a href="#isa"><code>isa</code></a> of course mandates an inheritance relationship. Other relationships include aggregation, delegation, and mocking.)</p> </dd> <dd> <p>By default, classes in Perl only perform the <code>UNIVERSAL</code> role. To mark that your own classes perform other roles, override <a href="#does"><code>DOES</code></a> appropriately.</p> </dd> <dd> <p>There is a relationship between roles and classes, as each class implies the existence of a role of the same name. There is also a relationship between inheritance and roles, in that a subclass that inherits from an ancestor class implicitly performs any roles its parent performs. Thus you can use <a href="#does"><code>DOES</code></a> in place of <a href="#isa"><code>isa</code></a> safely, as it will return true in all places where <a href="#isa"><code>isa</code></a> will return true (provided that any overridden <a href="#does"><code>DOES</code></a> <em>and</em> <a href="#isa"><code>isa</code></a> methods behave appropriately).</p> </dd> </li> <dt><strong><a name="can" class="item"><code>$obj->can( METHOD )</code></a></strong> <dt><strong><code>CLASS->can( METHOD )</code></strong> <dt><strong><code>eval { VAL->can( METHOD ) }</code></strong> <dd> <p><a href="#can"><code>can</code></a> checks if the object or class has a method called <code>METHOD</code>. If it does, then it returns a reference to the sub. If it does not, then it returns <em>undef</em>. This includes methods inherited or imported by <a href="#_obj"><code>$obj</code></a>, <a href="#class"><code>CLASS</code></a>, or <a href="#val"><code>VAL</code></a>.</p> </dd> <dd> <p><a href="#can"><code>can</code></a> cannot know whether an object will be able to provide a method through AUTOLOAD (unless the object's class has overriden <a href="#can"><code>can</code></a> appropriately), so a return value of <em>undef</em> does not necessarily mean the object will not be able to handle the method call. To get around this some module authors use a forward declaration (see <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlsub.html">the perlsub manpage</a>) for methods they will handle via AUTOLOAD. For such 'dummy' subs, <a href="#can"><code>can</code></a> will still return a code reference, which, when called, will fall through to the AUTOLOAD. If no suitable AUTOLOAD is provided, calling the coderef will cause an error.</p> </dd> <dd> <p>You may call <a href="#can"><code>can</code></a> as a class (static) method or an object method.</p> </dd> <dd> <p>Again, the same rule about having a valid invocant applies -- use an <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#eval"><code>eval</code></a> block or <code>blessed</code> if you need to be extra paranoid.</p> </dd> </li> <dt><strong><a name="version" class="item"><code>VERSION ( [ REQUIRE ] )</code></a></strong> <dd> <p><a href="#version"><code>VERSION</code></a> will return the value of the variable <code>$VERSION</code> in the package the object is blessed into. If <code>REQUIRE</code> is given then it will do a comparison and die if the package version is not greater than or equal to <code>REQUIRE</code>.</p> </dd> <dd> <p><a href="#version"><code>VERSION</code></a> can be called as either a class (static) method or an object method.</p> </dd> </li> </dl> <p> </p> <hr /> <h1><a name="exports">EXPORTS</a></h1> <p>None by default.</p> <p>You may request the import of three functions (<a href="#isa"><code>isa</code></a>, <a href="#can"><code>can</code></a>, and <a href="#version"><code>VERSION</code></a>), however it is usually harmful to do so. Please don't do this in new code.</p> <p>For example, previous versions of this documentation suggested using <a href="#isa"><code>isa</code></a> as a function to determine the type of a reference:</p> <pre> use UNIVERSAL 'isa';</pre> <pre> $yes = isa $h, "HASH"; $yes = isa "Foo", "Bar";</pre> <p>The problem is that this code will <em>never</em> call an overridden <a href="#isa"><code>isa</code></a> method in any class. Instead, use <code>reftype</code> from <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Scalar/Util.html">the Scalar::Util manpage</a> for the first case:</p> <pre> use Scalar::Util 'reftype';</pre> <pre> $yes = reftype( $h ) eq "HASH";</pre> <p>and the method form of <a href="#isa"><code>isa</code></a> for the second:</p> <pre> $yes = Foo->isa("Bar");</pre> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> UNIVERSAL - base class for ALL classes</span></strong></big> </td></tr> </table> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de