Created
November 29, 2010 10:51
-
-
Save armins/719820 to your computer and use it in GitHub Desktop.
show inheritance in perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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