moo-problem.txt

Moo type-checking problem
mail@pastecode.io avatar
unknown
plain_text
24 days ago
3.3 kB
8
Indexable
Never
As you can see below, the check if the value passed to the "sizing" attribute
in the "PerfAnalysisDocument" module if it is an object of class
"PerfAnalysisSizing" fails on one system, but not on another.

The versions:
Failing system: perl 5.32, Type::Tiny 2.004000, Moo 2.005005
Not failing system: perl 5.38, Type::Tiny 2.004000, Moo 2.005005

I inserted a debug print into

	Method/Generate/Accessor.pm:_validate_codulatable()

just before the "eval { \&$value; 1 }" (line 716) and the value looks perfectly
normal:

	value=[InstanceOf["PerfAnalysisSizing"]]

#============================================================================
# stack trace
#============================================================================
$ perl -MCarp=verbose ./cperfutil -help
Invalid isa 'Type::Tiny::Class=HASH(0x5572678566b8)' for PerfAnalysisDocument->sizing could not be converted to a coderef: Can't use string ("PerfAnalysisSizing") as a HASH ref while "strict refs" in use at (eval 251) line 46.
 at /opt/CPerfTools-2.1.0/local/lib/perl5/Method/Generate/Accessor.pm line 728.
	Method::Generate::Accessor::_validate_codulatable(Method::Generate::Accessor=HASH(0x557269f61d00), "isa", Type::Tiny::Class=HASH(0x5572678566b8), "PerfAnalysisDocument->sizing") called at /opt/CPerfTools-2.1.0/local/lib/perl5/Method/Generate/Accessor.pm line 121
	Method::Generate::Accessor::generate_method(Method::Generate::Accessor=HASH(0x557269f61d00), "PerfAnalysisDocument", "sizing", HASH(0x557269f821f8)) called at /opt/CPerfTools-2.1.0/local/lib/perl5/Moo.pm line 121
	Moo::has("sizing", "is", "ro", "isa", Type::Tiny::Class=HASH(0x5572678566b8)) called at /opt/CPerfTools-2.1.0/lib/PerfAnalysisDocument.pm line 102
	require PerfAnalysisDocument.pm called at ./cperfutil line 29
	main::BEGIN() called at /opt/CPerfTools-2.1.0/lib/PerfAnalysisDocument.pm line 0
	eval {...} called at /opt/CPerfTools-2.1.0/lib/PerfAnalysisDocument.pm line 0
Compilation failed in require at ./cperfutil line 29.
BEGIN failed--compilation aborted at ./cperfutil line 29.

#============================================================================
# simplified (extremely) structure
#============================================================================

################## cperfutil (main) #################
#!/usr/bin/perl

use PerfAnalysisSizing;
use PerfAnalysisDocument;

my $config = PerfAnalysisConfig->new(version => $version);
my $sizing = PerfAnalysisSizing->new(config => $config);
my $doc = PerfAnalysisDocument->new(config => $config, sizing => $sizing);

# do some work...

################## PerfAnalysisSizing #################
package PerfAnalysisSizing;
use Moo;
use Types::Standard qw( Str Num Bool CodeRef Undef Int InstanceOf HashRef );
use namespace::clean;

has config => (
    is      => 'ro',
    isa     => InstanceOf['PerfAnalysisConfig'],
);  

# various methods...
1;

################## PerfAnalysisDocument #################
package PerfAnalysisDocument;
use Moo;
use Types::Standard qw( Str Num Bool CodeRef Undef Int InstanceOf HashRef );
use namespace::clean;

has config => (
    is      => 'ro',
    isa     => InstanceOf['PerfAnalysisConfig'],
);

# line 101
has sizing => (
    is      => 'ro',
    isa     => InstanceOf['PerfAnalysisSizing'],
);

# methods...
1;
Leave a Comment