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 Maxim Grigoriev Outlines Perl XML Binding Framework PXB

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 Maxim Grigoriev Outlines Perl XML Binding Framework PXB (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

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Último (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Maxim Grigoriev Outlines Perl XML Binding Framework PXB

  • 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