XML-Rabbit icon indicating copy to clipboard operation
XML-Rabbit copied to clipboard

Best way to create objects from non-XML sources?

Open sillitoe opened this issue 7 years ago • 0 comments

Hi,

I've used XML::Rabbit to help me parse XML files into objects for lots of different projects. It works beautifully (thank you).

I now need to create some of these XML::Rabbit objects from a non-XML source (ie database) and export as XML. I would like to reuse as much code as possible.

I'm using MooseX::Templated to export the XML and that works fine (see test case).

I just need to be able to create the objects manually rather than from XML source, eg

Foo->new( id => 'my id', bars => [ Foo::Bar->new() ] );

Doing this currently makes XML::Rabbit complain about missing required attributes and not providing file, xml, etc.

Attribute (_node), passed as (node), is required at constructor Foo::Bar::new 
(defined at /[...]/.plenv/versions/5.12.5/lib/perl5/site_perl/5.12.5/XML/Rabbit/Sugar.pm line 136) line 30

So, do you have any suggestions for the best way to go about bypassing all the XML::Rabbit requirements and just fallback to the requirements of the Moose attributes?

I'm playing about with a test case here. I'm happy to write it up as a PR if you could point me in the right direction.

Best,

Ian

sillitoe avatar Nov 02 '18 16:11 sillitoe