| 1 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | package Document::OOXML::Rels; | ||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Class representing ".rels" (relationships) files in OOXML | ||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 2 | has xml => ( | |||||||||
| 10 | is => 'ro', | ||||||||||
| 11 | isa => 'XML::LibXML::Document', | ||||||||||
| 12 | required => 1, | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 2 | has xpc => ( | |||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | isa => 'XML::LibXML::XPathContext', | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 2 | has basedir => ( | |||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | isa => 'Str', | ||||||||||
| 24 | required => 0, | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | 2 | my $RELATIONSHIPS_NS = 'http://schemas.openxmlformats.org/package/2006/relationships'; | |||||||||
| 29 | |||||||||||
| 30 | 12 | ▶ | sub new_from_xml { | ||||||||
|
Subroutine
new_from_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 31 | 12 | my $class = shift; | |||||||||
| 32 | 12 | my $xml_data = shift; | |||||||||
| 33 | 12 | my $basedir = shift; | |||||||||
| 34 | |||||||||||
| 35 | 12 | my $xml = XML::LibXML->load_xml( string => $xml_data ); | |||||||||
| 36 | 12 | my $xpc = XML::LibXML::XPathContext->new(); | |||||||||
| 37 | 12 | $xpc->registerNs('r' => $RELATIONSHIPS_NS); | |||||||||
| 38 | |||||||||||
| 39 | 12 | return $class->new( | |||||||||
| 40 | xml => $xml, | ||||||||||
| 41 | xpc => $xpc, | ||||||||||
| 42 | basedir => $basedir, | ||||||||||
| 43 | ); | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | 21 | ▶ | sub get_part_relation_by_type { | ||||||||
|
Subroutine
get_part_relation_by_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | 21 | my $self = shift; | |||||||||
| 49 | 21 | my $part_type = shift; | |||||||||
| 50 | |||||||||||
| 51 | 21 | my ($part_relation) = $self->xpc->findnodes( | |||||||||
| 52 | "/r:Relationships/r:Relationship[\@Type='$part_type']", | ||||||||||
| 53 | $self->xml->documentElement, | ||||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | 21 | return $self->_extract_relation_data($part_relation); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | 16 | ▶ | sub get_part_relation_by_id { | ||||||||
|
Subroutine
get_part_relation_by_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 61 | 16 | my $self = shift; | |||||||||
| 62 | 16 | my $part_id = shift; | |||||||||
| 63 | |||||||||||
| 64 | 16 | my ($part_relation) = $self->xpc->findnodes( | |||||||||
| 65 | "/r:Relationships/r:Relationship[\@Id='$part_id']", | ||||||||||
| 66 | $self->xml->documentElement, | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | 16 | return $self->_extract_relation_data($part_relation); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 37 | ▶ | sub _extract_relation_data { | ||||||||
|
Subroutine
_extract_relation_data: called CC=3 SCAR=11.0
| |||||||||||
| 73 | 37 | my $self = shift; | |||||||||
| 74 | 37 | my $part_relation = shift; | |||||||||
| 75 | 37 | ▶ | return unless $part_relation; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | 32 | my $id = $self->xpc->findvalue('@Id', $part_relation); | |||||||||
| 78 | 32 | my $type = $self->xpc->findvalue('@Type', $part_relation); | |||||||||
| 79 | 32 | my $part_name = $self->xpc->findvalue('@Target', $part_relation); | |||||||||
| 80 | |||||||||||
| 81 | return { | ||||||||||
| 82 | 32 | ▶ | id => $id, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | type => $type, | ||||||||||
| 84 | part_name => $self->basedir | ||||||||||
| 85 | ? join('/', $self->basedir, $part_name) | ||||||||||
| 86 | : $part_name, | ||||||||||
| 87 | }; | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 2 | __PACKAGE__->meta->make_immutable(); | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||