in reply to Re^2: Use Storable for storing XML::LibXML object
in thread Use Storable for storing XML::LibXML object

Then you may be able to define a couple of hooks for freezing and thawing XML::LibXML::Element objects

# these are completely untested! sub XML::LibXML::Elemment::STORABLE_freeze { my $self = shift; $self->toString; } sub XML::LibXML::Elemment::STORABLE_thaw { my $class = shift; my (undef, $str) = @_; XML::LibXML->parse_xml(string => $str)->documentElement; }

See the "Hooks" section in the Storable documentation.

Replies are listed 'Best First'.
Re^4: Use Storable for storing XML::LibXML object
by ikegami (Pope) on Jul 05, 2014 at 19:51 UTC
    Note that if you serialize two elements from the same document, they will be part of two documents when deserialized.
Re^4: Use Storable for storing XML::LibXML object
by buff (Acolyte) on Jul 07, 2014 at 10:27 UTC

    Thanks very much for your help. After some tweaking it seems to work. I've ended up with this code:

    sub XML::LibXML::Element::STORABLE_freeze { shift->toString } sub XML::LibXML::Element::STORABLE_attach { 'XML::LibXML'->load_xml(string => pop)->documentElement }
Re^4: Use Storable for storing XML::LibXML object
by buff (Acolyte) on Jul 05, 2014 at 17:38 UTC

    Thank you very much! I'll give it a try on Monday and post the result here.