Core Function IsOverloaded
From Sputnik Wiki
IsOverloaded( <class>, <overload> )
Contents |
Description
Check if a given cast/operator overload exists within a class.
class
A class to check for the overload.
overload
A single overload or an array of overloads.
Return Value
Success: true
Failure: false
Remarks
None.
Example
Class Account { my $Name; my $Credits; Function __construct($Name = "", $Credits = 0) { $this->$Name = $Name; $this->$Credits = $Credits; } Operator "string" // This will be done whenever somebody uses (string)$ourclass { return "Account '$Name' Credits '$Credits'"; } Operator "++" { $Credits++; } Operator "==" (Account $t) { return $Name == $t->$Name && $Credits == $t->$Credits; } }; $nacc = New Account("FoX", 777); say IsOverloaded($nacc, "int32"); # false say IsOverloaded($nacc, "string"); # true say IsOverloaded($nacc, "--"); # false say IsOverloaded($nacc, "++"); # true say IsOverloaded($nacc, "=="); # true say IsOverloaded($nacc, "!="); # false # All at once say IsOverloaded($nacc, array("string", "++", "==")); # true say IsOverloaded($nacc, array("string", "--", "++", "==")); # false