Hello,
I have a role lying around in my code that requires an XML source and
provides a trait that allows an attribute's value to default to a
specified XPath. I've found it useful as a quick way of extracting
snippets of XML data into an object.
I now need to refactor this out to somewhere else in my code - so
figured it might be an appropriate time to ask if this would be useful
to stick on cpan? Clashes with other modules?
Also, the trait works by changing options through: around
'_process_options' (lazy =3D> 1 and default =3D> sub { ... }) - does that
sound sane? I couldn't see anything on the extending moose docs about
what is considered typical (or safe/stable) to hook into - is there a
consensus on this?
#################################
package PDBx::NoAtom;
use PDBx::Moose;
use MooseX::Types::Moose qw/ Str ArrayRef /;
use namespace::autoclean;
our $VERSION =3D "0.01";
with 'MooseX::XPathBuilder';
has 'id' =3D> (
=A0=A0=A0 traits=A0=A0=A0=A0=A0 =3D> [ 'XPathBuilder' ],
=A0=A0=A0 is=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> 'ro',
=A0=A0=A0 isa=A0=A0=A0=A0=A0=A0=A0=A0 =3D> Str,
=A0=A0=A0 xpath=A0=A0=A0=A0=A0=A0 =3D> '//PDBx:entry[1]/@id',
);
map {
=A0=A0=A0 has 'primary_citation_' . $_ =3D> (
=A0=A0=A0=A0=A0=A0=A0 traits=A0=A0=A0=A0=A0 =3D> [ 'XPathBuilder' ],
=A0=A0=A0=A0=A0=A0=A0 is=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> 'ro',
=A0=A0=A0=A0=A0=A0=A0 isa=A0=A0=A0=A0=A0=A0=A0=A0 =3D> Str,
=A0=A0=A0=A0=A0=A0=A0 xpath=A0=A0=A0=A0=A0=A0 =3D>
q{//PDBx:citationCategory/PDBx:citation[@id=3D'primary']/PDBx:} . $_,
=A0=A0=A0 );
} qw(
=A0=A0=A0 country
=A0=A0=A0 journal_abbrev
=A0=A0=A0 journal_volume
=A0=A0=A0 page_first
=A0=A0=A0 page_last
=A0=A0=A0 pdbx_database_id_PubMed
=A0=A0=A0 title
=A0=A0=A0 year
);
#################################
use PDBx::NoAtom;
my $pdb =3D PDBx::NoAtom->new( xml_file =3D> '1cuk-noatom.xml.gz' );
$pdb->id=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0 # '1CUK'
$pdb->primary_citation_title;=A0=A0 # 'Crystal structure of DNA recombinati=
on
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #=A0 protein RuvA and a model for its
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #=A0 binding to the Holliday junction.'
#################################
All comments appreciated.
Cheers,
--
Ian Sillitoe