"Sputnik" help  
Sputnik Help
Language Reference - Classes - Class Magic Functions - Get

Class Magic Functions - Get

This allows a class to override features that try get a value such as ["key"] for example:

// define a class
class test
{
    my $arr;
    Function __Construct()
    {
        $arr = array();
    }
    Function __Get($index)
    {
        return $arr[$index];
    }
    Function __Set($index, $value)
    {
        $arr[$index] = $value;
    }
}

// create new instance
my $a = new test();

// use the __set function to set some values
$a["Cat"] = "Meow";
$a["Dog"] = "Woof";

// now use the __get function to return them values
say $a["Cat"];
say $a["Dog"];

// PRINTS
// Meow
// Woof

To override everything be sure to check out GetFromEnd.

A full list of all possible magic functions can be found here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org