use Class::HPLOO ;
class Point[0.01] extends GeoForms {
sub Point ($x , $y) {
$this->{x} = $x ;
$this->{y} = $y ;
}
sub move_x( $mv_x ) {
$this->{x} += $mv_x ;
}
sub move_y( $mv_y ) {
$this->{y} += $mv_y ;
}
}
####
package Point ;
use strict qw(vars) ;
use vars qw(@ISA $VERSION) ;
push(@ISA , qw(GeoForms)) ;
$VERSION = '0.01' ;
sub new {
my $class = shift ;
my $this = bless({} , $class) ;
my ( $x , $y ) = @_ ;
$this->{x} = $x ;
$this->{y} = $y ;
return $this ;
}
sub move_x {
my $this = shift ;
my $mv_x = shift ;
$this->{x} += $mv_x ;
}
sub move_y {
my $this = shift ;
my $mv_y = shift ;
$this->{y} += $mv_y ;
}
1;
##
##
use Class::HPLOO ;
class Point {
sub Point ($x , $y) {
$this->{x} = $x ;
$this->{y} = $y ;
}
sub move_x( $mv_x ) {
$this->{x} += $mv_x ;
}
sub[C] void move_y( SV* self , int mv_y ) {
SV* sv_y = *hv_fetch( (HV*)SvRV(self) , "y" , strlen("y") , 0) ;
int y = SvIV(sv_y) + mv_y ;
sv_setsv_mg(sv_y , sv_2mortal(newSViv(y)) ) ;
}
}
##
##
sub[C] void move_y( SV* self , int mv_y ) {
int y = self->{y}->int + mv_y ;
self->{y} = int2sv(y) ;
}
##
##
sub[C] SV* get_xy_ref( SV* self ) {
AV* ret = newAV() ; // create an array.
ret->[0] = self->{x} ; // store at $ret[0], filling the array and creating the new element.
ret->[1] = self->{y} ; // store at $ret[1].
return \{ret} ; // return a reference to the array.
}
##
##
sub[C] SV* get_xy_ref( SV* self ) {
SV* self_hv = (HV*) SvRV(self) ;
SV* sv_x = *hv_fetch( self_hv , "x" , strlen("x") , 0 ) ;
SV* sv_y = *hv_fetch( self_hv , "y" , strlen("y") , 0 ) ;
AV* ret = newAV() ;
av_fill(ret , 1) ;
av_store(ret , 0 , newSV(0)) ;
av_store(ret , 1 , newSV(0)) ;
sv_setsv( *av_fetch(ret, 0 ,0) , sv_x ) ;
sv_setsv( *av_fetch(ret, 1 ,0) , sv_y ) ;
return newRV_inc( ret ) ;
}