In the current Perl class experiment, is there a way to override a method and refer to super?

I did not find anything mentioning this anywhere, but it is such a basic feature of class based programming, that I can't imagine it is not there, somewhere, somehow.

class One { method do_it {say 1} }
class Two : isa(One) { method do_it { super()->do_it; say 2} } # or so...
3 points · 3 comments · view on lemmy.world

3 Comments

breadsmasher@lemmy.world · 1 pts · 3y (2 replies)

Is this what you are looking for

https://stackoverflow.com/a/29287248

snake_cased@lemmy.ml · 1 pts · 3y

I can do One::do_it($self) or One->can('do_it')->($self), but that seems very ugly and against the pattern.

snake_cased@lemmy.ml · 1 pts · 3y

But if you are referring to: my $sub = sub { $self->SUPER::method(@_) }; or actually only $self->SUPER::method(@_)

no, this is seemingly no possible (and what I am looking for, in one way or another) - this is the super() from my pseudo code above and there is no SUPER. This seems to be a bless based feature...

Sorry, I take that back, $self->SUPER::do_it(); does work!

Thanks!