File Coverage

blib/lib/Catmandu/FedoraCommons/Model/datastreamHistory.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Catmandu::FedoraCommons::Model::datastreamHistory - Perl model for the Fedora 'getDatastreamHistory' REST call
4              
5             =head1 SYNOPSIS
6              
7             use Catmandu::FedoraCommons;
8            
9             my $fedora = Catmandu::FedoraCommons->new('http://localhost:8080/fedora','fedoraAdmin','fedoraAdmin');
10            
11             my $obj = $fedora->getDatastreamHistory(pid => 'demo:29', dsID => 'DC')->parse_content;
12            
13             {
14             'pid' => 'demo:29' ,
15             'dsID' => 'DC',
16             'profile' => [
17             {
18             'dsLabel' => 'Dublin Core Record for this object' ,
19             'dsVersionID' => 'DC1.0' ,
20             'dsCreateDate' => '2008-07-02T05:09:43.234Z' ,
21             'dsState' => 'A' ,
22             'dsMIME' => 'text/xml' ,
23             'dsFormatURI' => 'http://www.openarchives.org/OAI/2.0/oai_dc/' ,
24             'dsControlGroup' => 'X' ,
25             'dsSize' => 626,
26             'dsVersionable' => 'true' ,
27             'dsInfoType' => '' ,
28             'dsLocation' => 'demo:29+DC+DC1.0' ,
29             'dsLocationType' => '' ,
30             'dsChecksumType' => 'DISABLED' ,
31             'dsChecksum' => 'none' ,
32             }
33             ]
34             }
35            
36             =head1 SEE ALSO
37              
38             L<Catmandu::FedoraCommons>
39              
40             =cut
41             package Catmandu::FedoraCommons::Model::datastreamHistory;
42              
43 1     1   49529 use XML::LibXML;
  0            
  0            
44              
45             sub parse {
46             my ($class,$xml) = @_;
47             my $dom = XML::LibXML->load_xml(string => $xml);
48             $dom->getDocumentElement()->setNamespace('http://www.fedora.info/definitions/1/0/management/','m');
49              
50             my @nodes = $dom->findnodes("/m:datastreamHistory/m:datastreamProfile");
51              
52             my $result;
53            
54             for my $node (@nodes) {
55             my @sub_nodes = $node->findnodes("./*");
56            
57             my $profile;
58            
59             for my $sub_node (@sub_nodes) {
60             my $name = $sub_node->nodeName;
61             my $value = $sub_node->textContent;
62            
63             $profile->{$name} = $value;
64             }
65            
66             push @{ $result->{profile} }, $profile;
67             }
68            
69             my $pid = $dom->firstChild()->getAttribute('pid');
70             $result->{pid} = $pid;
71              
72             my $dsID = $dom->firstChild()->getAttribute('dsID');
73             $result->{dsID} = $dsID;
74              
75             return $result;
76             }
77              
78             1;