The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

VSO - Very Small Objects

SYNOPSIS

package Plane;

use VSO;

has 'width' => (
  is        => 'ro',
  isa       => 'Int',
);

has 'height' => (
  is        => 'ro',
  isa       => 'Int',
);

has 'points' => (
  is        => 'rw',
  isa       => 'ArrayRef[Point2d]',
  required  => 0,
);


package Point2d;

use VSO;

has 'plane' => (
  is        => 'ro',
  isa       => 'Plane',
  weak_ref  => 1,
);

has 'x' => (
  is        => 'rw',
  isa       => 'Int',
  where     => sub {
    my $s = shift;
    $_ >= 0 && $_ <= $s->plane->width
  }
);

has 'y' => (
  is        => 'rw',
  isa       => 'Int',
  where     => sub {
    my $s = shift;
    $_ >= 0 && $_ <= $s->plane->height
  }
);

after 'x' => sub {
  my ($s, $new_value, $old_value) = @_;
  warn "Moving $s from x$old_value to x$new_value";
}

after 'y' => sub {
  my ($s, $new_value, $old_value) = @_;
  warn "Moving $s from y$old_value to y$new_value";
}

package Point3d;

use VSO;

extends 'Point2d';

has 'z' => (
  is      => 'rw',
  isa     => 'Int',
);

DESCRIPTION

VSO aims to offer a declarative OO style for Perl with very little overhead, without being overly-minimalist.

NOTE: This is not a drop-in replacement for Moose, Moo, Mo, Mouse or anything like that.

AUTHOR

John Drago <jdrago_999@yahoo.com>

LICENSE

This software is Free software and may be used and redistributed under the same terms as perl itself.