0

i have a simple test class using Moose, with a XML::LibXML::Document attribute, but get an error when I use this test class. The test class is:

package moosetest;

use strict;
use warnings;

use XML::LibXML;

use Moose;

has dom => ( is => 'rw', isa => 'XML::LibXML::Document', required => 0, handles => qr/^( findnodes | documentElement | setDocumentElement | toString | toFile )$/x );


1;

Then it's used in test.pl:

use XML::LibXML;

use moosetest;

my $tt = moosetest->new();

And when I run test.pl, I get an error:

The dom attribute is trying to delegate to a class which has not been loaded - XML::LibXML::Document

I'm using perlbrew, XML::LibXML is installed (I can instantiate a XML::LibXML::Document object without using Moose), Moose has been successfully installed, too.

Looks like I'm missing something important here, but i can't find the source of my problem...

Thanks for any help.

Francois.

francois
  • 61
  • 2
  • 8

1 Answers1

1

Moose::Meta::Attribute::_find_delegate_metaclass uses Moose::Util::_is_package_loaded which looks for XML::LibXML::Document in @INC. However, the package XML::LibXML::Document is inside of XML/LibXML.pm.

Using an array instead regex for handles avoids this problem:

handles => [ qw( findnodes documentElement setDocumentElement toString toFile ) ],
t0mppa
  • 3,983
  • 5
  • 37
  • 48
  • OK, it works with the change you suggested. Still strange to me... I will fix the code, but it used to work with a previous version of perl (5.16), XML::LibXML and Moose, the error appeared when I tried to upgrade my development environment... – francois Feb 14 '14 at 15:34
  • OK, answering to myself: it used to work with Moose 2.0802 and fails with the latest version. May be due to the change in 2.1100 (changed the class loader)... – francois Feb 19 '14 at 14:08