in reply to Thoughts on new 'class' OO in upcoming perl
A lot of your issues can be resolved by using the :common attribute. For example:
class Foo { field $x :param = 0; field $y :param = 0; method create :common ( %args ) { if ( $args{x} < 0 ) { return undef; } else { return $class->new( %args ); } } } my $foo = Foo->create( x => $x, y => $y ) or do_some_error_handling();
Note that this is supported in Object::Pad but not in the first round of implementation for the class keyword (likely to be included in Perl 5.38). As Object::Pad is the testing ground for the class keyword, we can hopefully take it as an indication that :common will be supported in a forthcoming version of Perl, hopefully Perl 5.40.
|
---|