NAME

XML::RelaxNG::Compact::PXB - create perl XML (RelaxNG Compact) data binding API

VERSION

Version 0.08

DESCRIPTION

The instance of this class is capable of generating the API tree of the perl objects based on XML (RelaxNG compact) schema described as perl data structures. If you have bunch of XML schemes ( and able to convert them into RelaxNG Compact ) and hate to waste your time by writing DOM tree walking code then this module may help you. Of course POD will be created automatically as well. Also, it will build the tests suit automatically as well and provide perltidy and perlcritic config files for you to assure the absence of problems in your API. The Perl::Critic test will be performed as part of the tests suit.

See XML::RelaxNG::Compact::DataModel for more details and examples.

SYNOPSIS

 ###
 use    XML::RelaxNG::Compact::PXB;

 # express your schema 

 my $subelement =  {  'attrs'  => {value => 'scalar', type => 'scalar', port => 'scalar',  xmlns => 'nsid2'},
                                              elements => [],
                                              text => 'unless:value',
               };
 my $model = = {  'attrs'  => {id => 'scalar', type => 'scalar', xmlns => 'nsid'},
             elements => [
                           [subelement => $subelement ]
                         ],
            };
 # define Namespace registry for your schemes
 
 my $nsreg = { 'nsid' => 'http://nsid/URI',  'nsid2' => 'http://nsid2/URI'};
 
 # create API builder with your desired parameters 
 #
 my $api_builder =   XML::RelaxNG::Compact::PXB->new({ 
                                       top_dir =>   "/topdir/",
                                       nsregistry => $nsreg,
                                       datatypes_root =>   "Datatypes,
                                       schema_version =>   "1.0",
                                       test_dir =>   "/topdir/t"});

 #### this call will build everything - API,tests, helper modules
 #### where  name parameter is the name of your root element  - "nsid:mymodel"
 #
 #   it will create versioned API under /topdir/Datatypes/v1_0/nsid/ for nsid namespace prefix
 #  and /topdir/Datatypes/v1_0/nsid2/ for nsid2 namespace prefix
 #
 
 $api_builder->buildAPI('mymodel', $model);
 

 #### this call will build only test suit
 ####
 $api_builder->buildTests('mymodel', $model);

 ####

 #### this call will build only Helper modules under /topdir/Datatypes/v1_0/ -  namespace prefix mapping, basic element operations
 ####
 
 $api_builder->buildHelpers();

 ####

METHODS

new({})

creates new object, accepts reference to hash as parameters container where keys are:

  • DEBUG - set it to something defined to provide extra logging

  • top_dir - full pathname to the api root dir, for example test files will be placed as top_dir/test_dir Default: current directory

  • nsregistry - reference to the hash with {ns_prefix => ns_URI} pairs, it will be built into the Element class Default: just XSD and XSI namespaces

  • datatypes_root - name of the generated datatypes directory Default: XMLTypes

  • schema_version - version identifier for your XML schema Default: 1.0

  • test_dir - name for the test suit files ( relative to the <top_dir>) Default: t

  • footer - container of the object - POD::Credentials, used for printing POD footer with SEE ALSO, AUTHOR, COPYRIGHT, LICENSE

Possible ways to call new():

### with defaults
$api_builder =   XML::RelaxNG::Compact::PXB->new();

## passes hashref with explicit   parameters, for the next example:
## api will be created at /root/XMLTypes/v1_0/
## and tests files under - /root/t

$api_builder =   XML::RelaxNG::Compact::PXB->new({
                                          top_dir =>   "/root/",
                                          datatypes_root =>   "XMLTypes",
                                          nsregistry => { 'nsid' => 'nsURI'},
                                          schema_version =>   "1.0",
                                          test_dir =>   "t",
                                          footer => POD::Credentials->new({author=> 'Joe Doe'}),
                                          });

buildAPI()

builds XML binding API recursively accepts parameters:

  • name of the root element - undef by default

  • reference to the hash representing the RelaxNG Compact schema, empty hash ref by default

  • parent - is undef for the root element

returns $self

buildHelpers

shortcut to build Helper classes only, no arguments
returns $self

buildAM

prints accessors and mutators for the passed reference to array of names
returns $self

buildTests

shortcut to build test files  only, no arguments
returns $self

buildClass

builds single class on the filesystem and corresponded test file accepts parameters:

  • name of the element

  • hashref with the element definition

  • hashref with parent definition if its not the root element

returns $self

buildTest

auxiliary method
it builds test file for current class
accepts:

      reference to array with elements,
      reference to array with attributes,
      class name
      name of the package
      element name

returns: nothing

saying

prints string into the  file handler without new line

sayIt

prints string into the   file handler with new line added

AUTHOR

Maxim Grigoriev (FNAL), maxim_at_fnal_dot_gov

LICENSE

You should have received a copy of the Fermitools license with this software. If not, see <http://fermitools.fnal.gov/about/terms.html>

COPYRIGHT

Copyright(c) 2007-2008, Fermi Research Alliance (FRA)