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

Class Magic Functions - Slice

This allows a class to override all [] slice operations within Sputnik when used on a class.for example:

Class Slicer
{
    my $arr;
    Function __Construct($array)
    {
        $arr = $array;
    }
    Function __Slice($type, $offset, $end, $step)
    {
        say "Slice offset $offset end $end step $step";
        switch ($type)
        {
            case @SliceTypeNone:
                say "Type None";
                break;
            case @SliceTypeTo:
                say "Type To";
                break;
            case @SliceTypeFrom:
                say "Type From";
                break;
            case @SliceTypeFromTo:
                say "Type FromTo";
                break;
            case @SliceTypeFromToStep:
                say "Type FromToStep";
                break;
            case @SliceTypeFromStep:
                say "Type FromStep";
                break;
            case @SliceTypeReverse:
                say "Type Reverse";
                break;
            case @SliceTypeClone:
                say "Type Clone";
                break;
        }
        return array(); // splied array can be returned or new class instance
    }
}

$a = new Slicer(["A" rr "F"]);
$a[::-1];
$a[3::-1];
$a[4:5];
$a[4:5:7];
$a[:8];
$a[9:];
// PRINTS
// Slice offset -1 end 0 step -1
// Type Reverse
// Slice offset 3 end 0 step -1
// Type FromStep
// Slice offset 4 end 5 step 1
// Type FromTo
// Slice offset 4 end 5 step 7
// Type FromToStep
// Slice offset 0 end 8 step 1
// Type To
// Slice offset 9 end 0 step 1
// Type From

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

For a list of Slice Operator Types go here.


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