in reply to Re^3: Perl OOP
in thread Perl OOP
Nothing in Perl that I know of will prevent you from inheriting from such an object.
Ehhh… it's actually pretty easy to do in Moose/Moo/Class::Tiny. I mean, it's not rocket science to work around, but this should do the job:
use v5.16; package Example::Phone { use Moo; has number => (is => 'ro', required => 1); sub call { ... } # Make final sub BUILD { my $self = shift; die(sprintf '%s is final; %s cannot inherit', __PACKAGE__, ref +($self)) unless ref($self) eq __PACKAGE__; } } package Example::Phone::Mobile { use Moo; extends 'Example::Phone'; sub send_sms { ... } } my $number1 = Example::Phone->new(number => 1); my $number2 = Example::Phone::Mobile->new(number => 2); # dies
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Perl OOP
by tobyink (Canon) on Jul 05, 2017 at 10:27 UTC |