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

Class Magic Functions - SliceAssign

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

Class Slicer
{
    my $arr;
    Function __Construct($array)
    {
        $arr = $array;
    }
    Function __SliceAssign($type, $offset, $end, $step, $data)
    {
        say "Slice offset $offset end $end step $step";
        say "Slice Data $data";
        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 @SliceTypeColumnTo:
                say "Type Column To";
                break;
            case @SliceTypeColumnFrom:
                say "Type Column From";
                break;
            case @SliceTypeColumnFromTo:
                say "Type Column FromTo";
                break;
            case @SliceTypeColumnFromToStep:
                say "Type Column FromToStep";
                break;
            case @SliceTypeColumnFromStep:
                say "Type Column FromStep";
                break;
            case @SliceTypeColumnReverse:
                say "Type Column 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[:] = 777;
$a[::-1] = 777;
$a[3::-1]= 777;
$a[4:5]= 777;
$a[4:5:7]= 777;
$a[:8]= 777;
$a[9:]= 777;
// PRINTS
// Slice offset 0 end 0 step 0
// Slice Data 777
// Type Clone
// Slice offset -1 end 0 step -1
// Slice Data 777
// Type Reverse
// Slice offset 3 end 0 step -1
// Slice Data 777
// Type FromStep
// Slice offset 4 end 5 step 1
// Slice Data 777
// Type FromTo
// Slice offset 4 end 5 step 7
// Slice Data 777
// Type FromToStep
// Slice offset 0 end 8 step 1
// Slice Data 777
// Type To
// Slice offset 9 end 0 step 1
// Slice Data 777
// 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