I'm going to be producing XML based on some specified requirements. I'm pretty happy with using Class::Prototyped to produce the XML, but Moose is en vogue.

I glanced through the meta-programming facilities of Moose and it seems overly complicated for what I'm doing.

Do you see a module/approach that could improve on my approach to producing XML fields?

# produce XML using XML::Writer my $W = XML::Writer->new( DATA_INDENT => 4 , DATA_MODE => 1 ) ; # Here are the tags we must provide in the XML my @schema = qw(Id InsuranceType SC Password Leadcount Group_Code_List first_name last_name ); my $o = Class::Prototyped->new( xml => $W, lead => $lead, # Some XML elements simply need $lead->{$TagName} a +s their content, so we put them here getkey => { Id => 'lead_id' , InsuranceType => 'lead_type' , first_name => 'fname', last_name => 'lname', }, # Some XML elements have hardcoded values direct => { SC => 'ghi' } , # Some elements need to do some computation before +returning the content on the XML tag mkdataval => { 'Password' => sub { my($self)=@_; rand (1) > +0.5 ? 'Beta_User' : 'prodn_password' } , 'Leadcount' => sub { my($self)=@_; int(rand(1 +0)) } , 'Group_Code_List' => sub { my($self)=@_; '?' +}, }, postproc => sub { # dress up the XML, etc } ); $W->startTag('xmlpost'); for my $tag (@schema) { if (my $data_value = $o->direct->{$tag}) { $o->xml->dataElement($tag => $data_value); } elsif (my $lead_key = $o->getkey->{$tag}) { $o->xml->dataElement($tag => $o->lead->{$lead_key}); } elsif (my $closure = $o->mkdataval->{$tag}) { $o->xml->dataElement($tag => $closure->($o)) ; } elsif (my $slot = $o->reflect->getSlot($tag)) { $o->$tag; } } $W->endTag; $W->end;

In reply to object-oriented XML generation by metaperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.