Logo

Programming-Idioms

History of Idiom 73 > diff from v392 to v393

Edit summary for version 393 by daxim:
New Perl implementation by user [daxim]

Version 392

2017-05-12, 12:10:42

Version 393

2019-09-29, 08:54:51

Idiom #73 Create a factory

Create a factory named fact for any sub class of Parent and taking exactly one string str as constructor parameter.

Idiom #73 Create a factory

Create a factory named fact for any sub class of Parent and taking exactly one string str as constructor parameter.

Imports
use Safe::Isa;
Code
sub fact {
    my ($class, $str) = @_;
    return $class->new($str) if $class->$_isa('Parent');
}
Doc URL
http://p3rl.org/Safe::Isa