# Funky.pm use strict; use warnings; package Funky::Vertex; use Moose; use Data::Dump 'pp'; has 'X' => (is=>'rw', isa=>'Num'); has 'Y' => (is=>'rw', isa=>'Num'); around BUILDARGS => sub { my $orig = shift; my $class = shift; print "Vertex(<$_[0]>)\n"; if (@_==1 && !ref $_[0]) { # We were handed a single scalar, so we're expecting a string like "##.##,##.##" # representing the X and Y coordinates my @list = split /,/, $_[0]; print "\tV: ", pp(\@list), "\n"; return $class->$orig( X=>$list[0], Y=>$list[1] ); } else { return $class->$orig(@_); } }; package Funky::Rectangle; use Moose; use Data::Dump 'pp'; has 'LL' => (is=>'rw', isa=>'Funky::Vertex'); has 'UR' => (is=>'rw', isa=>'Funky::Vertex'); around BUILDARGS => sub { my $orig = shift; my $class = shift; print "Rectangle(<$_[0]>)\n"; if (@_==1 && !ref $_[0]) { # We were handed a single scalar, so we're expecting a string representing # a pair of vertices, like "##.##,##.##;##.##,##.##" # representing the LL and UR corners my @list = split /;/, $_[0]; print "\tRB: ", pp(\@list), "\n"; return $class->$orig( LL=>$list[0], UR=>$list[1] ); ### NOTE BELOW ### } else { return $class->$orig(@_); } }; 1;