SlideShare uma empresa Scribd logo
1 de 12
Maxim Grigoriev Fermi National Accelerator Laboratory   PXB:  Perl XML Binding
Outline of the talk   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Motivations   or Who needs Yet Another XML “framework” ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Model   XML element represented in perl, see  http://code.google.com/p/pxb/wiki/PXB  for complete docs: <element-variable>  =  {   attrs   =>   { attributes-definition  ,    xmlns   =>   ' string'  } ,   elements  =>   [ elements-definition   ] ,   text  =>  ' text-content' ,   sql   =>   {sql-mapping-definition} ,   } attributes-definition  = ( string   =>  ' attribute-value'  ) ( ,   attributes-definition )* attribute-value  =  scalar  | ( enum : ( string  ( ,  string )*))  elements-definition  = (  [  string  => (  <element-variable>  |  [   <element-variable>   ]  |  [  (  <element-variable>  ,)+  ]  |  [  ( [ <element-variable>   ] ,?)+  ]  )  ,   ' conditional-statement' ?  ])* text-content  =  scalar  |  conditional-statement conditional-statement  = (  unless  |  if  ) : ( variable-name  (,  variable-name )*) Example:   $parameter = {  attrs => { name => 'enum:name1,name2',  value => 'scalar',  xmlns => ‘nsid1'},   elements => [],   text => 'unless:value‘ };
Data Model ( continued... )   The rest of the model,  SQL  mapping: sql-mapping-definition  = ( sql-table-name   =>  {   sql-table-entry   }  ) (  ,  sql-mapping-definition )* sql-table-entry  = ( sql-entry-name   =>   {   entry-mapping   }  ) ( ,  sql-table-entry )* entry-mapping  =  value  =>  (  element-name  |  (  [ element-name  ( , element-name )+  ] )  )  ( ,   ' if-condition' )?  if-condition  =  if  =>  attribute-name   :  attribute-value sql-entry-name  =   string sql-table-name  =  string Example:   $parameter->{sql} = { tableName  => {  field1  => {value => ['value' , 'text'],   if => 'name:name1'},   field2  => {value => ['value' , 'text'],    if => 'name:name2'}, }    }
Data Model (still continued...)  What about complex types ? Lists, choice between different elements or choice between the elements with the same local name but from the different namespaces: For example:  elements => [parameter => [$parameter]]  -  defines list of  parameter   elements   elements => [parameter => $parameter]   -  defines single  parameter   element  elements => [parameter => [$parameter, $other_parameter]]   -  defines choice between two single  elements with different local names (for example  nmwg:parameter  and  nmwg:otherParameter ) elements => [parameter => [[$ns1_parameter], [$ns2_parameter]] ]   -  defines choice between two lists of  elements with the same local  name but belonged to different namespaces DONE WITH DATA MODEL...
Building API  Once your model is defined its very easy to create your API: use XML::RelaxNG::Compact::PXB; use   POD::Credentials ; my $api_builder =  XML::RelaxNG::Compact::PXB->new({ top_dir =>  &quot;/home/joedoe/API&quot;, datatypes_root =>  &quot;XMLTypes&quot;, nsregistry =>  { ’nsid1’ => ’http://some.org/nsURI’},  schema_version =>  &quot;1.0&quot;,  test_dir =>  &quot;t&quot;,  footer =>  POD::Credentials->new({author=> ’Joe Doe’}), }); $api_builder->buildAPI(‘myParameter’, $parameter); It will create package  XMLTypes::v1_0::nsid1::MyParameter  as:  /home/joedoe/API/XMLTypes/v1_0/nsid1/MyParameter.pm Some helper classes and   the test suit: /home/joedoe/API/t/XMLTypes::v1_0::nsid1::MyParameter.t   /home/joedoe/API/t/conf/perlcriticrc /home/joedoe/API/t/conf/perltidyrc /home/joedoe/API/test.pl
All the goodies ( aka API introspection )  Every generated class has  constructor  with the same interface, it accepts single hash ref as an argument and every class implements the same set of methods.  Every method in the class follows the same prototype.  Every object can be initialized from the XML fragment ( scalar ), DOM object or reference to the hash. Of course it can be serialized back into the DOM or XML. It  knows  how to handle complex types. There are many XML schema  where each element is identified by unique attribute named  id . The generated API can build a map of such elements and supports  addById, removeById  to allow faster lookup for the multiple elements in the list. There is a special call named  registerNamespaces  for returning  hash of the all namespaces registered for  the root object  Every element is mapped on the particular namespace by the namespace prefix. Example of API utilization ,  perldoc XMLTypes/v1_0/nsid1/MyParameter  to see full list of calls  : use XMLTypes::v1_0::nsid1::MyParameter; my $object = XMLTypes::v1_0::nsid1::MyParameter->new({  xml =>  ‘ <nsid1:myParameter xmlns:nsid1=&quot;http://some.org/nsURI&quot; name=“name1”  value=“newValue &quot; />’ }); print ‘Name:’ . $object->get_name . ‘ Value:’ . $object->get_value;
SQL Mapping  Supported by  querySQL  call, it goes recursively through the objects tree and returns ref to hash with contents of the mapped XML elements. For the previously defined  parameter  element: Example:   XML serilaized into $object:  <nsid1:myParameter name='name1' value='100/> <nsid1:myParameter name='name2' value='200/> call  $object->querySQL($hash_ref_to_return); $hash_ref_to_return   is  { tableName => { field1 => '100' , field2 => '200'} }   where it can be easily passed to any of  SQL ORM  frameworks.  For example: in case of  Class::DBI: my @records =  TableName->search(%{ $hash_ref_to_return} ); or with minor refactoring in  Rose::DB::Object my @records = TableName::Manager->get_tablenames( query => [ field1 => { eq =>  $hash_ref_to_return->{field1} }, field2 => { eq =>  $hash_ref_to_return->{field2} }, ]  );
The rest of the story Centralized logging is supported by  Log::Log4perl  module Each module is throughly documented with  pod Test suit is built for each generated class There are  perlcritic  and  perltidy  profiles created for the API and  perlcritic  parsing is an integral part of the module testing Essentially, one can create a bunch of RelaxNG or XML schema derived  CPAN modules in a matter of minutes and pollute  XML::  namespace even more Or one can start schema derived API with properly formed classes and follow the same style and utilize automated tests to assure enterprise level quality of the software  (and perl needs it badly)
Problems, Plans  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Questions ? Oh, and yes, perl is indeed unDead ! Links: Links: PXB project on Google code –  http://code.google.com/p/pxb/w/list perfSONAR-PS wiki -  https://wiki.internet2.edu/confluence/display/PSPS

Mais conteúdo relacionado

Mais procurados

JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptAung Baw
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closuresKnoldus Inc.
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with ScalaNeelkanth Sachdeva
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHPRob Knight
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - OperatorsWebStackAcademy
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
 
EmberConf 2021 - Crossfile Codemodding with Joshua Lawrence
EmberConf 2021 - Crossfile Codemodding with Joshua LawrenceEmberConf 2021 - Crossfile Codemodding with Joshua Lawrence
EmberConf 2021 - Crossfile Codemodding with Joshua LawrenceJoshua Lawrence
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern PerlDave Cross
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedAyesh Karunaratne
 

Mais procurados (19)

JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
Apache Velocity 1.6
Apache Velocity 1.6Apache Velocity 1.6
Apache Velocity 1.6
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
EmberConf 2021 - Crossfile Codemodding with Joshua Lawrence
EmberConf 2021 - Crossfile Codemodding with Joshua LawrenceEmberConf 2021 - Crossfile Codemodding with Joshua Lawrence
EmberConf 2021 - Crossfile Codemodding with Joshua Lawrence
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
Apache Velocity
Apache VelocityApache Velocity
Apache Velocity
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 

Semelhante a Pxb For Yapc2008

Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPStephan Schmidt
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPstubbles
 
Rspec API Documentation
Rspec API DocumentationRspec API Documentation
Rspec API DocumentationSmartLogic
 
AWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewAWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewDan Morrill
 
Xml Java
Xml JavaXml Java
Xml Javacbee48
 
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationIQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationTed Leung
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objectshiren.joshi
 
ApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML ParsingApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML ParsingTed Leung
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 

Semelhante a Pxb For Yapc2008 (20)

Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
 
Rspec API Documentation
Rspec API DocumentationRspec API Documentation
Rspec API Documentation
 
AWS Hadoop and PIG and overview
AWS Hadoop and PIG and overviewAWS Hadoop and PIG and overview
AWS Hadoop and PIG and overview
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Framework
FrameworkFramework
Framework
 
Xml Java
Xml JavaXml Java
Xml Java
 
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationIQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
 
Javascript2839
Javascript2839Javascript2839
Javascript2839
 
Json
JsonJson
Json
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objects
 
ApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML ParsingApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML Parsing
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Pxb For Yapc2008

  • 1. Maxim Grigoriev Fermi National Accelerator Laboratory PXB: Perl XML Binding
  • 2.
  • 3.
  • 4. Data Model XML element represented in perl, see http://code.google.com/p/pxb/wiki/PXB for complete docs: <element-variable> = { attrs => { attributes-definition , xmlns => ' string' } , elements => [ elements-definition ] , text => ' text-content' , sql => {sql-mapping-definition} , } attributes-definition = ( string => ' attribute-value' ) ( , attributes-definition )* attribute-value = scalar | ( enum : ( string ( , string )*)) elements-definition = ( [ string => ( <element-variable> | [ <element-variable> ] | [ ( <element-variable> ,)+ ] | [ ( [ <element-variable> ] ,?)+ ] ) , ' conditional-statement' ? ])* text-content = scalar | conditional-statement conditional-statement = ( unless | if ) : ( variable-name (, variable-name )*) Example: $parameter = { attrs => { name => 'enum:name1,name2', value => 'scalar', xmlns => ‘nsid1'}, elements => [], text => 'unless:value‘ };
  • 5. Data Model ( continued... ) The rest of the model, SQL mapping: sql-mapping-definition = ( sql-table-name => { sql-table-entry } ) ( , sql-mapping-definition )* sql-table-entry = ( sql-entry-name => { entry-mapping } ) ( , sql-table-entry )* entry-mapping = value => ( element-name | ( [ element-name ( , element-name )+ ] ) ) ( , ' if-condition' )? if-condition = if => attribute-name : attribute-value sql-entry-name = string sql-table-name = string Example: $parameter->{sql} = { tableName => { field1 => {value => ['value' , 'text'], if => 'name:name1'}, field2 => {value => ['value' , 'text'], if => 'name:name2'}, } }
  • 6. Data Model (still continued...) What about complex types ? Lists, choice between different elements or choice between the elements with the same local name but from the different namespaces: For example: elements => [parameter => [$parameter]] - defines list of parameter elements elements => [parameter => $parameter] - defines single parameter element elements => [parameter => [$parameter, $other_parameter]] - defines choice between two single elements with different local names (for example nmwg:parameter and nmwg:otherParameter ) elements => [parameter => [[$ns1_parameter], [$ns2_parameter]] ] - defines choice between two lists of elements with the same local name but belonged to different namespaces DONE WITH DATA MODEL...
  • 7. Building API Once your model is defined its very easy to create your API: use XML::RelaxNG::Compact::PXB; use POD::Credentials ; my $api_builder = XML::RelaxNG::Compact::PXB->new({ top_dir => &quot;/home/joedoe/API&quot;, datatypes_root => &quot;XMLTypes&quot;, nsregistry => { ’nsid1’ => ’http://some.org/nsURI’}, schema_version => &quot;1.0&quot;, test_dir => &quot;t&quot;, footer => POD::Credentials->new({author=> ’Joe Doe’}), }); $api_builder->buildAPI(‘myParameter’, $parameter); It will create package XMLTypes::v1_0::nsid1::MyParameter as: /home/joedoe/API/XMLTypes/v1_0/nsid1/MyParameter.pm Some helper classes and the test suit: /home/joedoe/API/t/XMLTypes::v1_0::nsid1::MyParameter.t /home/joedoe/API/t/conf/perlcriticrc /home/joedoe/API/t/conf/perltidyrc /home/joedoe/API/test.pl
  • 8. All the goodies ( aka API introspection ) Every generated class has constructor with the same interface, it accepts single hash ref as an argument and every class implements the same set of methods. Every method in the class follows the same prototype. Every object can be initialized from the XML fragment ( scalar ), DOM object or reference to the hash. Of course it can be serialized back into the DOM or XML. It knows how to handle complex types. There are many XML schema where each element is identified by unique attribute named id . The generated API can build a map of such elements and supports addById, removeById to allow faster lookup for the multiple elements in the list. There is a special call named registerNamespaces for returning hash of the all namespaces registered for the root object Every element is mapped on the particular namespace by the namespace prefix. Example of API utilization , perldoc XMLTypes/v1_0/nsid1/MyParameter to see full list of calls : use XMLTypes::v1_0::nsid1::MyParameter; my $object = XMLTypes::v1_0::nsid1::MyParameter->new({ xml => ‘ <nsid1:myParameter xmlns:nsid1=&quot;http://some.org/nsURI&quot; name=“name1” value=“newValue &quot; />’ }); print ‘Name:’ . $object->get_name . ‘ Value:’ . $object->get_value;
  • 9. SQL Mapping Supported by querySQL call, it goes recursively through the objects tree and returns ref to hash with contents of the mapped XML elements. For the previously defined parameter element: Example: XML serilaized into $object: <nsid1:myParameter name='name1' value='100/> <nsid1:myParameter name='name2' value='200/> call $object->querySQL($hash_ref_to_return); $hash_ref_to_return is { tableName => { field1 => '100' , field2 => '200'} } where it can be easily passed to any of SQL ORM frameworks. For example: in case of Class::DBI: my @records = TableName->search(%{ $hash_ref_to_return} ); or with minor refactoring in Rose::DB::Object my @records = TableName::Manager->get_tablenames( query => [ field1 => { eq => $hash_ref_to_return->{field1} }, field2 => { eq => $hash_ref_to_return->{field2} }, ] );
  • 10. The rest of the story Centralized logging is supported by Log::Log4perl module Each module is throughly documented with pod Test suit is built for each generated class There are perlcritic and perltidy profiles created for the API and perlcritic parsing is an integral part of the module testing Essentially, one can create a bunch of RelaxNG or XML schema derived CPAN modules in a matter of minutes and pollute XML:: namespace even more Or one can start schema derived API with properly formed classes and follow the same style and utilize automated tests to assure enterprise level quality of the software (and perl needs it badly)
  • 11.
  • 12. Questions ? Oh, and yes, perl is indeed unDead ! Links: Links: PXB project on Google code – http://code.google.com/p/pxb/w/list perfSONAR-PS wiki - https://wiki.internet2.edu/confluence/display/PSPS