| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package XML::Malware; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 23083 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 7 |  |  |  |  |  |  | $VERSION = eval $VERSION;  # see L | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 468 | use XML::Compile; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | use XML::Compile::Schema; | 
| 11 |  |  |  |  |  |  | use XML::Compile::Util qw/pack_type/; | 
| 12 |  |  |  |  |  |  | use XML::LibXML; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | my $type = pack_type 'http://xml/metadataSharing.xsd', 'malwareMetaData'; | 
| 15 |  |  |  |  |  |  | XML::Compile->addSchemaDirs(__FILE__); | 
| 16 |  |  |  |  |  |  | use constant MYNS => 'http://xml/metadataSharing.xsd'; | 
| 17 |  |  |  |  |  |  | XML::Compile->knownNamespace(&MYNS => 'metadataSharing.xsd'); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # Preloaded methods go here. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub new { | 
| 22 |  |  |  |  |  |  | my $class = shift; | 
| 23 |  |  |  |  |  |  | my $args = shift; | 
| 24 |  |  |  |  |  |  | my $self = {}; | 
| 25 |  |  |  |  |  |  | bless($self,$class); | 
| 26 |  |  |  |  |  |  | $self->_hash($args); | 
| 27 |  |  |  |  |  |  | return($self); | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub in { | 
| 31 |  |  |  |  |  |  | my $self = shift; | 
| 32 |  |  |  |  |  |  | my $xml = shift; | 
| 33 |  |  |  |  |  |  | return(undef) unless($xml); | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | my $s = XML::Compile::Schema->new(); | 
| 36 |  |  |  |  |  |  | $s->importDefinitions(MYNS); | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | my $read = $s->compile(READER => $type); | 
| 39 |  |  |  |  |  |  | my $h = $read->($xml); | 
| 40 |  |  |  |  |  |  | return(undef) unless($h && ref($h) eq 'HASH'); | 
| 41 |  |  |  |  |  |  | $self->_hash($h); | 
| 42 |  |  |  |  |  |  | return($self->_hash()); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub out { | 
| 46 |  |  |  |  |  |  | my $self = shift; | 
| 47 |  |  |  |  |  |  | my $s       = XML::Compile::Schema->new(); | 
| 48 |  |  |  |  |  |  | $s->importDefinitions(MYNS); | 
| 49 |  |  |  |  |  |  | my $doc    = XML::LibXML::Document->new('1.0', 'UTF-8'); | 
| 50 |  |  |  |  |  |  | my $write  = $s->compile(WRITER => $type); | 
| 51 |  |  |  |  |  |  | my $xml    = $write->($doc, $self->_hash()); | 
| 52 |  |  |  |  |  |  | return $xml->toString(); | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | # accessors | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub _hash { | 
| 58 |  |  |  |  |  |  | my ($self,$v) = @_; | 
| 59 |  |  |  |  |  |  | $self->{'_hash'} = $v if(defined($v)); | 
| 60 |  |  |  |  |  |  | return($self->{'_hash'}); | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | 1; | 
| 64 |  |  |  |  |  |  | __END__ |