Calling initialize in this example results in:
Show quoted text
> perl Fruit.pm
Can't locate object method "new" via package
"MooseX::Singleton::Role::Object" at
/.../perl/lib/site_perl/5.10.0/MooseX/Singleton/Role/Object.pm line 13.
If I change the last line of the initialize method in
MooseX::Singleton::Role::Object from:
return $class->SUPER::new(@args);
To:
return $class->new(@args);
The attached works. I realize that isn't a complete solution. Am I using
this incorrectly or should this work?
Thanks!
Cymen
Subject: | Fruit.pm |
#!/usr/bin/perl
package Fruit;
use Moose::Role;
has 'type' => (
is => 'rw',
isa => 'Str',
#required => 1,
);
1;
#-----------------------------------------------------------
package SingleApple;
use MooseX::Singleton;
with 'Fruit';
has 'crispness' => (
is => 'rw',
isa => 'Int',
default => 5,
);
1;
#-----------------------------------------------------------
package main;
#use SingleApple;
my $a = SingleApple->initialize({ type=>'Golden Delicious' });
#my $a = SingleApple->instance({ type=>'Golden Delicious' });
print "Type: ", $a->type, "\n";
print "Crispness: ", $a->crispness, "\n";