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

Thank you. Querying down from the node is enough in my case.
  • Comment on Re^2: Use Storable for storing XML::LibXML object

Replies are listed 'Best First'.
Re^3: Use Storable for storing XML::LibXML object
by tobyink (Abbot) on Jul 05, 2014 at 12:23 UTC

    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.

      Note that if you serialize two elements from the same document, they will be part of two documents when deserialized.

      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 }

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