Skip to content

Instantly share code, notes, and snippets.

@armins
Created November 29, 2010 10:51
Show Gist options
  • Save armins/719820 to your computer and use it in GitHub Desktop.
Save armins/719820 to your computer and use it in GitHub Desktop.
show inheritance in perl
use Data::Dumper;
package Package1;
sub new
{
my($class) = shift;
my(%params) = @_;
bless {
"CONTENT" => $params{"content"},
}, $class;
}
sub shout
{
my $self = shift;
print "SHOUT\n";
}
package Package2;
@ISA = (Packerl1);
sub new
{
my($class) = shift;
my(%params) = @_;
my($self) = Package1->new(@_);
$self->{"ADDITIONAL_CONTENT"} = $params{"additional_content"};
return(bless($self,$class));
}
sub shout
{
my($self) = shift;
print "SCREAM\n";
}
package main;
$p1 = Package1->new("content" => "this is the content");
$p2 = Package2->new("content" => 'less content', "additional_content" => 'more_content');
$p1->shout;
$p2->shout;
print Dumper $p1;
print Dumper $p2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment