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 => 1 and default => 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 = "0.01";

with 'MooseX::XPathBuilder';

has 'id' => (
    traits      => [ 'XPathBuilder' ],
    is          => 'ro',
    isa         => Str,
    xpath       => '//PDBx:entry[1]/@id',
);

map {
    has 'primary_citation_' . $_ => (
        traits      => [ 'XPathBuilder' ],
        is          => 'ro',
        isa         => Str,
        xpath       =>
q{//PDBx:citationCategory/PDBx:citati...@id='primary']/PDBx:} . $_,
    );
} qw(
    country
    journal_abbrev
    journal_volume
    page_first
    page_last
    pdbx_database_id_PubMed
    title
    year
);

#################################

use PDBx::NoAtom;

my $pdb = PDBx::NoAtom->new( xml_file => '1cuk-noatom.xml.gz' );

$pdb->id                        # '1CUK'

$pdb->primary_citation_title;   # 'Crystal structure of DNA recombination
                                    #  protein RuvA and a model for its
                                    #  binding to the Holliday junction.'

#################################


All comments appreciated.

Cheers,

--
Ian Sillitoe

Reply via email to