Guest User

Untitled

a guest
Jul 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. {
  2. package Foo;
  3. use strict;
  4. use warnings;
  5.  
  6. sub new {
  7. my $class = shift;
  8. my %self = map { $_ } @_;
  9. bless \%self, $class;
  10. }
  11.  
  12. sub what {
  13. my $self = shift;
  14. return "foo";
  15. }
  16. }
  17.  
  18. {
  19. package Bar;
  20. use strict;
  21. use warnings;
  22. use base qw/ Foo /;
  23.  
  24. my $obj = Foo->new();
  25.  
  26. # how do i get this sub to overwrite the what() in Foo?
  27. sub what {
  28. my $self = shift;
  29. return "bar";
  30. }
  31.  
  32. print $obj->what;
  33. }
Add Comment
Please, Sign In to add comment