roman has asked for the wisdom of the Perl Monks concerning the following question:
I have a subclass extending parent class method via inner() and augment
package C1; use Moose; sub html { my $this = shift; return '<html>' . '<body>' . inner() . '</body>' . '</html>'; } package C2; use Moose; extends 'C1'; augment html => sub { return 'C2'; };
I want to add another augmentable method, which content is not mandatory, i.e. I don't want to supply augment in every subclass.warn C2->new->html; # yields # <html><body>C2</body></html>
package C1; use Moose; sub html { my $this = shift; return '<html>' . $this->head . '<body>' . inner() . '</body>' . '</html>'; } sub head { return '<head>' . (inner() || '') . '</head>'; } package C2; use Moose; extends 'C1'; augment html => sub { return 'C2'; };
But if I don't supply the content of head method in subclass then the content of html method is used:
warn C2->new->html; # yields # <html><head>C2</head><body>C2</body></html>
So is it possible to use more than one augmentable method, with some of them having "optional" content?
Thanks for any reply including those: "You should not do this, ..."
Roman
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Moose - two augmented methods in one class
by tobyink (Canon) on Jan 09, 2012 at 14:50 UTC | |
by tobyink (Canon) on Jan 09, 2012 at 15:19 UTC | |
by zwon (Abbot) on Jan 09, 2012 at 15:25 UTC | |
by tobyink (Canon) on Jan 09, 2012 at 15:37 UTC | |
by tobyink (Canon) on Jan 09, 2012 at 16:13 UTC | |
by stvn (Monsignor) on Jan 11, 2012 at 05:19 UTC | |
|