package Robo::Arm; sub new { bless { } , shift } sub pick { print "I am grabbing " . $_[1] } 1; package Robo::Feet; sub new { bless { Position => [11,0] } , shift } sub walk { my $c = shift; my ( $x, $y ) = @{$c->{Position}} ; if ( $x > 10 || $y > 10 ) { print "Out of boundary. I stop walk" } else { print "I start walk from pos $x $y " } } 1; package Robo; use parent -norequire , 'Robo::Arm', 'Robo::Feet'; sub new { bless { Arm => new Robo::Arm(), Feet => new Robo::Feet(), }, shift } 1; package main; my $robo = new Robo; $robo -> pick ( "Apple" ) ; $robo -> walk ; #### package Robo::Arm; sub new { bless { } , shift } sub pick { print "I am grabbing " . $_[1] } 1; package Robo::Feet; sub new { bless { Position => [11,0] } , shift } sub walk { my $c = shift; my ( $x, $y ) = @{$c->{Position}} ; if ( $x > 10 || $y > 10 ) { print "Out of boundary. I stop walk" } else { print "I start walk at pos $x $y " } } 1; package Robo; sub AUTOLOAD { our $AUTOLOAD ; $AUTOLOAD =~ /([\w]+)$/; my $meth = $1; my $c = shift; my $can = undef; foreach ( keys %$c ) { if ( $c->{$_}->can ( $meth ) ) { eval "\$c->{\$_}->${meth} (\@_) " ; $can++ } } die "There's no $meth method anywhere" unless $can; } sub new { bless { Arm => new Robo::Arm(), Feet => new Robo::Feet(), }, shift } 1; package main; my $robo = new Robo; $robo -> walk ; $robo -> pick ( "Apple" ) ;