| 1 | package TEI::Lite::Document; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ##==================================================================## | ||||||||||||||||||||||||||||
| 4 | ## Libraries and Variables ## | ||||||||||||||||||||||||||||
| 5 | ##==================================================================## | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | require 5.006; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use TEI::Lite::Element; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use I18N::LangTags qw( is_language_tag ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | our $VERSION = "0.60"; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | ##==================================================================## | ||||||||||||||||||||||||||||
| 22 | ## Constructor(s)/Deconstructor(s) ## | ||||||||||||||||||||||||||||
| 23 | ##==================================================================## | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 26 | ## new ## | ||||||||||||||||||||||||||||
| 27 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 28 | sub new | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | ## Pull in what type of an object we will be. | ||||||||||||||||||||||||||||
| 31 | 2 | my $type = shift; | |||||||||||||||||||||||||||
| 32 | ## Grab a copy of our parameters. | ||||||||||||||||||||||||||||
| 33 | 2 | my %params = @_; | |||||||||||||||||||||||||||
| 34 | ## Declare a variable that will later become our object instance. | ||||||||||||||||||||||||||||
| 35 | 2 | my $self; | |||||||||||||||||||||||||||
| 36 | ## Check to see if a filename is defined, if it is then attempt to load | ||||||||||||||||||||||||||||
| 37 | ## it ... otherwise just init a blank object. | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | if( defined( $params{ 'Filename' } ) ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | $self = _load_teilite_file( %params ); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | elsif( defined( $params{ 'String' } ) ) | ||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 0 | $self = _load_teilite_string( %params ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | else | ||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 2 | $self = _init_object_instance( %params ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | ## Determine what exact class we will be blessing this instance into. | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | my $class = ref( $type ) || $type; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $type || $type
MC/DC0%0/2
ref $type || $type
ref $type
$type
Truth table33%1/3
A || B
A= ref $typeB= $type
| |||||||||||||||||||||||||||||
| 52 | ## Bless the class for it is good [tm]. | ||||||||||||||||||||||||||||
| 53 | 2 | bless( $self, $class ); | |||||||||||||||||||||||||||
| 54 | ## Send it back to the caller all happy like. | ||||||||||||||||||||||||||||
| 55 | 2 | return( $self ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 59 | ## DESTROY ## | ||||||||||||||||||||||||||||
| 60 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 61 | sub DESTROY | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | ## This is mainly a placeholder to keep things like mod_perl happy. | ||||||||||||||||||||||||||||
| 64 | 0 | return; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | ##==================================================================## | ||||||||||||||||||||||||||||
| 68 | ## Method(s) ## | ||||||||||||||||||||||||||||
| 69 | ##==================================================================## | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 72 | ## addBackMatter ## | ||||||||||||||||||||||||||||
| 73 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 74 | sub addBackMatter | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addBackMatter: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | ## We need to look to see if we are a corpus document. | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | 0 | croak( "Corpus documents do not contain back matter." ); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ## Look to see if a back matter is already defined for this active text. | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( !defined( $self->{ "back" }->{ $self->{ "active" } } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | ## Create the back matter element. | ||||||||||||||||||||||||||||
| 88 | 0 | my $back = tei_back(); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | ## Insert the back matter after the body element. | ||||||||||||||||||||||||||||
| 91 | 0 | $self->{ "text" }->{ $self->{ "active" } }->appendChild( $back ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | ## Stick a reference into the hash tree. | ||||||||||||||||||||||||||||
| 94 | 0 | $self->{ "back" }->{ $self->{ "active" } } = $back; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | return( $back ); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 0 | carp( "The specified text has a pre-existing back element. " . | |||||||||||||||||||||||||||
| 101 | "Only one back element may exist per text. " ); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 108 | ## addCompositeBackMatter ## | ||||||||||||||||||||||||||||
| 109 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 110 | sub addCompositeBackMatter | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addCompositeBackMatter: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | ## Do some error checking ... | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if( ( $self->{ "Corpus" } != 0 ) || ( $self->{ "Composite" } != 0 ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"Corpus"} != 0 or $self->{"Composite"} != 0
MC/DC0%0/2
$self->{"Corpus"} != 0 or $self->{"Composite"} != 0
$self->{"Corpus"} != 0
$self->{"Composite"} != 0
Truth table0%0/3
A or B
A= $self->{"Corpus"} != 0B= $self->{"Composite"} != 0
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 0 | croak( "This method only works on TEI composite documents." ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | ## Look to see if a back matter is already defined for this active text. | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if( !defined( $self->{ "back" }->{ "Composite" } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | ## Create the back matter element. | ||||||||||||||||||||||||||||
| 124 | 0 | my $back = tei_back(); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | ## Find the top text node and the last child of that node. | ||||||||||||||||||||||||||||
| 127 | 0 | my( $node ) = $self->{DOM}->findnodes( '//TEI.2/text' ); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | ## Append the back element onto the text node. | ||||||||||||||||||||||||||||
| 130 | 0 | $node->appendChild( $back ); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | ## Stick a reference into the hash tree. | ||||||||||||||||||||||||||||
| 133 | 0 | $self->{ "back" }->{ $self->{ "Composite" } } = $back; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return( $back ); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | else | ||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 0 | carp( "The specified text has a pre-existing composite back element. " . | |||||||||||||||||||||||||||
| 140 | "Only one back element may exist per composite document. " ); | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | return; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 147 | ## addCompositeFrontMatter ## | ||||||||||||||||||||||||||||
| 148 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 149 | sub addCompositeFrontMatter | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addCompositeFrontMatter: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | ## Do some error checking ... | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if( ( $self->{ "Corpus" } != 0 ) || ( $self->{ "Composite" } != 0 ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"Corpus"} != 0 or $self->{"Composite"} != 0
MC/DC0%0/2
$self->{"Corpus"} != 0 or $self->{"Composite"} != 0
$self->{"Corpus"} != 0
$self->{"Composite"} != 0
Truth table0%0/3
A or B
A= $self->{"Corpus"} != 0B= $self->{"Composite"} != 0
| |||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||
| 156 | 0 | croak( "This method only works on TEI composite documents." ); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | ## Look to see if a back matter is already defined for this active text. | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if( !defined( $self->{ "front" }->{ "Composite" } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||
| 162 | ## Create the back matter element. | ||||||||||||||||||||||||||||
| 163 | 0 | my $front = tei_front(); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | ## Find the top text node and the first child of that node. | ||||||||||||||||||||||||||||
| 166 | 0 | my( $node ) = $self->{DOM}->findnodes( '//TEI.2/text' ); | |||||||||||||||||||||||||||
| 167 | 0 | my $child = $node->firstChild; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | ## Insert the front element before all the rest of the child nodes. | ||||||||||||||||||||||||||||
| 170 | 0 | $node->insertBefore( $front, $child ); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | ## Stick a reference into the hash tree. | ||||||||||||||||||||||||||||
| 173 | 0 | $self->{ "front" }->{ $self->{ "Composite" } } = $front; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | return( $front ); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | else | ||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||
| 179 | 0 | carp( "The specified text has a pre-existing composite " . | |||||||||||||||||||||||||||
| 180 | "front element. Only one back element may exist per " . | ||||||||||||||||||||||||||||
| 181 | "composite document. " ); | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | return; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 188 | ## addDocument ## | ||||||||||||||||||||||||||||
| 189 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 190 | sub addDocument | ||||||||||||||||||||||||||||
| 191 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addDocument: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | ## Do some error checking to ensure that we are operating on a | ||||||||||||||||||||||||||||
| 195 | ## corpus document. | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if( $self->{ "Corpus" } == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 0 | croak( "Can only add additional documents to TEI corpus documents." ); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | ## Create a new TEI document. | ||||||||||||||||||||||||||||
| 202 | 0 | $self->{ "document" }->{ $self->{ "Corpus" } } = | |||||||||||||||||||||||||||
| 203 | TEI::Lite::Document->new(); | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | ## Add the document to the corpus DOM. | ||||||||||||||||||||||||||||
| 206 | $self->{ "DOM" }->documentElement->appendChild( | ||||||||||||||||||||||||||||
| 207 | 0 | $self->{ "document" }->{ $self->{ "Corpus" } }->documentElement() ); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | ## Increment the corpus document count. | ||||||||||||||||||||||||||||
| 210 | 0 | $self->{ "Corpus" }++; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | ## Return the new corpus document count. | ||||||||||||||||||||||||||||
| 213 | 0 | return( $self->{ "Corpus" } ); | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 217 | ## addFrontMatter ## | ||||||||||||||||||||||||||||
| 218 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 219 | sub addFrontMatter | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addFrontMatter: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 221 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | ## We need to look to see if we are a corpus document. | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||
| 226 | 0 | croak( "Corpus documents do not contain front matter." ); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | ## Look to see if a back matter is already defined for this active text. | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if( !defined( $self->{ "front" }->{ $self->{ "active" } } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||
| 232 | ## Create the back matter element. | ||||||||||||||||||||||||||||
| 233 | 0 | my $front = tei_front(); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | ## Insert the back matter after the body element. | ||||||||||||||||||||||||||||
| 236 | $self->{ "text" }->{ $self->{ "active" } }-> | ||||||||||||||||||||||||||||
| 237 | 0 | insertBefore( $front, $self->{ "body" }->{ $self->{ "active" } } ); | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | ## Stick a reference into the hash tree. | ||||||||||||||||||||||||||||
| 240 | 0 | $self->{ "front" }->{ $self->{ "active" } } = $front; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | return( $front ); | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | else | ||||||||||||||||||||||||||||
| 245 | { | ||||||||||||||||||||||||||||
| 246 | 0 | carp( "The specified text has a pre-existing back element. " . | |||||||||||||||||||||||||||
| 247 | "Only one back element may exist per text. " ); | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 254 | ## addHeader ## | ||||||||||||||||||||||||||||
| 255 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 256 | sub addHeader | ||||||||||||||||||||||||||||
| 257 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addHeader: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||
| 258 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | ## Determine what type of header we are adding. | ||||||||||||||||||||||||||||
| 261 | 1 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||
| 263 | ## Call the default constructor for a TEI::Lite::Header. | ||||||||||||||||||||||||||||
| 264 | 0 | my $header = TEI::Lite::Header->new( Type => 'Corpus' ); | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | ## Stick a reference to this in the document hash for easy | ||||||||||||||||||||||||||||
| 267 | ## access later. | ||||||||||||||||||||||||||||
| 268 | 0 | $self->{ "header" } = $header; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | ## Find the root element of a document. | ||||||||||||||||||||||||||||
| 271 | 0 | my $root = shift( @{ $self->{ "DOM" }->find( "teiCorpus.2" ) } ); | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | ## We need to find the firstChild of this root element. | ||||||||||||||||||||||||||||
| 274 | 0 | my $child = $root->firstChild; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | ## Finally insert into the document before the firstChild. | ||||||||||||||||||||||||||||
| 277 | 0 | $root->insertBefore( $header, $child ); | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | return( $header ); | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | else | ||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | ## Call the default constructor for a TEI::Lite::Header. | ||||||||||||||||||||||||||||
| 284 | 1 | my $header = TEI::Lite::Header->new(); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | ## Stick a reference to this in the document hash for easy | ||||||||||||||||||||||||||||
| 287 | ## access later. | ||||||||||||||||||||||||||||
| 288 | 0 | $self->{ "header" } = $header; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | ## Find the root element of a document. | ||||||||||||||||||||||||||||
| 291 | 0 | my $root = shift( @{ $self->{ "DOM" }->find( "TEI.2" ) } ); | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | ## We need to find the firstChild of this root element. | ||||||||||||||||||||||||||||
| 294 | 0 | my $child = $root->firstChild; | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | ## Finally insert into the document before the firstChild. | ||||||||||||||||||||||||||||
| 297 | 0 | $root->insertBefore( $header, $child ); | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | return( $header ); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 304 | ## addText ## | ||||||||||||||||||||||||||||
| 305 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 306 | sub addText | ||||||||||||||||||||||||||||
| 307 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
addText: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 308 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if( ( $self->{ "Corpus" } != 0 ) || ( $self->{ "Composite" } == 0 ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"Corpus"} != 0 or $self->{"Composite"} == 0
MC/DC0%0/2
$self->{"Corpus"} != 0 or $self->{"Composite"} == 0
$self->{"Corpus"} != 0
$self->{"Composite"} == 0
Truth table0%0/3
A or B
A= $self->{"Corpus"} != 0B= $self->{"Composite"} == 0
| |||||||||||||||||||||||||||||
| 311 | { | ||||||||||||||||||||||||||||
| 312 | 0 | croak( "Can only add additional texts to a TEI composite document." ); | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | ## Create a new text node for inclusion ... | ||||||||||||||||||||||||||||
| 316 | 0 | $self->{ "text" }->{ $self->{ "Composite" } } = tei_text(); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | ## Find the group element in the DOM tree. | ||||||||||||||||||||||||||||
| 319 | 0 | my( $node ) = $self->{ "DOM" }->findnodes( '//TEI.2/text/group' ); | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | ## Append the child into the tree. | ||||||||||||||||||||||||||||
| 322 | 0 | $node->appendChild( $self->{ "text" }->{ $self->{ "Composite" } } ); | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | ## Increment the corpus document count. | ||||||||||||||||||||||||||||
| 325 | 0 | $self->{ "Composite" }++; | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | ## Return the new corpus document count. | ||||||||||||||||||||||||||||
| 328 | 0 | return( $self->{ "Composite" } ); | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 332 | ## AUTOLOAD ## | ||||||||||||||||||||||||||||
| 333 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 334 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 336 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | ## Pull in AUTOLOAD ... | ||||||||||||||||||||||||||||
| 339 | 0 | my $function = ( split( /::/, $AUTOLOAD ) )[3]; | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | ## Return the AUTOLOAD call on the DOM tree. | ||||||||||||||||||||||||||||
| 342 | 0 | return( $self->{ "DOM" }->$function( @_ ) ); | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 346 | ## getActiveDocument ## | ||||||||||||||||||||||||||||
| 347 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 348 | sub getActiveDocument | ||||||||||||||||||||||||||||
| 349 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getActiveDocument: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 350 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if( $self->{ "Corpus" } == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||
| 354 | 0 | croak( "TEI composite and unitary documents do not contain other " . | |||||||||||||||||||||||||||
| 355 | "TEI documents." ); | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | ## Return the active text ... | ||||||||||||||||||||||||||||
| 359 | 0 | return( $self->{ "active" } ); | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 363 | ## getActiveText ## | ||||||||||||||||||||||||||||
| 364 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 365 | sub getActiveText | ||||||||||||||||||||||||||||
| 366 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getActiveText: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 367 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||
| 371 | 0 | croak( "TEI corpus documents do not contain texts." ); | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | ## Return the active text ... | ||||||||||||||||||||||||||||
| 375 | 0 | return( $self->{ "active" } ); | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 379 | ## getBackMatter ## | ||||||||||||||||||||||||||||
| 380 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 381 | sub getBackMatter | ||||||||||||||||||||||||||||
| 382 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getBackMatter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 383 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||
| 387 | 0 | carp( "TEI corpus documents do not directly contain back matter. " . | |||||||||||||||||||||||||||
| 388 | "Please acccess each individual document contained within " . | ||||||||||||||||||||||||||||
| 389 | "the corpus document to get the back matter for that " . | ||||||||||||||||||||||||||||
| 390 | "document." ); | ||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 0 | return( $self->{ "back" }->{ $self->{ "active" } } ); | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 397 | ## getBody ## | ||||||||||||||||||||||||||||
| 398 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 399 | sub getBody | ||||||||||||||||||||||||||||
| 400 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getBody: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 401 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||
| 405 | 0 | carp( "TEI corpus documents do not directly contain body elements. " . | |||||||||||||||||||||||||||
| 406 | "Please acccess each individual document contained within " . | ||||||||||||||||||||||||||||
| 407 | "the corpus document to get the body elements for that " . | ||||||||||||||||||||||||||||
| 408 | "document." ); | ||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 0 | return( $self->{ "body" }->{ $self->{ "active" } } ); | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 415 | ## getCompositeBackMatter ## | ||||||||||||||||||||||||||||
| 416 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 417 | sub getCompositeBackMatter | ||||||||||||||||||||||||||||
| 418 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getCompositeBackMatter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 419 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||
| 423 | 0 | carp( "TEI corpus documents do not directly contain back matter. " . | |||||||||||||||||||||||||||
| 424 | "Please acccess each individual document contained within " . | ||||||||||||||||||||||||||||
| 425 | "the corpus document to get the back matter for that " . | ||||||||||||||||||||||||||||
| 426 | "document." ); | ||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 0 | return( $self->{ "back" }->{ $self->{ "Composite" } } ); | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 433 | ## getCompositeFrontMatter ## | ||||||||||||||||||||||||||||
| 434 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 435 | sub getCompositeFrontMatter | ||||||||||||||||||||||||||||
| 436 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getCompositeFrontMatter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 437 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | { | ||||||||||||||||||||||||||||
| 441 | 0 | carp( "TEI corpus documents do not directly contain front matter. " . | |||||||||||||||||||||||||||
| 442 | "Please acccess each individual document contained within " . | ||||||||||||||||||||||||||||
| 443 | "the corpus document to get the front matter for that " . | ||||||||||||||||||||||||||||
| 444 | "document." ); | ||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 0 | return( $self->{ "front" }->{ $self->{ "Composite" } } ); | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 451 | ## getDocument ## | ||||||||||||||||||||||||||||
| 452 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 453 | sub getDocument | ||||||||||||||||||||||||||||
| 454 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getDocument: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 455 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | ## We need to do a simple sanity check. | ||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if( $self->{ "Corpus" } == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||
| 460 | 0 | croak( "TEI corpus documents are the only document type containing " . | |||||||||||||||||||||||||||
| 461 | "other TEI documents. " ); | ||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | ## Return the document associated with the value in "active". | ||||||||||||||||||||||||||||
| 465 | 0 | return( $self->{ "document" }->{ $self->{ "active" } } ); | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 469 | ## getDocuments ## | ||||||||||||||||||||||||||||
| 470 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 471 | sub getDocuments | ||||||||||||||||||||||||||||
| 472 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getDocuments: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 473 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | ## We need to do a simple sanity check. | ||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if( $self->{ "Corpus" } == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | { | ||||||||||||||||||||||||||||
| 478 | 0 | croak( "TEI corpus documents are the only document type containing " . | |||||||||||||||||||||||||||
| 479 | "other TEI documents. " ); | ||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | ## Declare a variable to hold our results. | ||||||||||||||||||||||||||||
| 483 | 0 | my @documents; | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | ## Loop through each of the documents and return a reference to | ||||||||||||||||||||||||||||
| 486 | ## that document. | ||||||||||||||||||||||||||||
| 487 | 0 | foreach( keys( %{ $self->{ "document" } } ) ) | |||||||||||||||||||||||||||
| 488 | { | ||||||||||||||||||||||||||||
| 489 | 0 | push( @documents, $self->{ "document" }->{ $_ } ); | |||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | ## If we call ourselves in a scalar context, return the | ||||||||||||||||||||||||||||
| 493 | ## number of corpus documents. | ||||||||||||||||||||||||||||
| 494 | 0 | ▶ | return( wantarray ? @documents : scalar( @documents ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 498 | ## getDocumentLang ## | ||||||||||||||||||||||||||||
| 499 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 500 | sub getDocumentLang | ||||||||||||||||||||||||||||
| 501 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getDocumentLang: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 502 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 0 | return( $self->{ "DOM" }->documentElement->getAttribute( "lang" ) ); | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 508 | ## getFrontMatter ## | ||||||||||||||||||||||||||||
| 509 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 510 | sub getFrontMatter | ||||||||||||||||||||||||||||
| 511 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getFrontMatter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 512 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 515 | { | ||||||||||||||||||||||||||||
| 516 | 0 | carp( "TEI corpus documents do not directly contain front matter. " . | |||||||||||||||||||||||||||
| 517 | "Please acccess each individual document contained within " . | ||||||||||||||||||||||||||||
| 518 | "the corpus document to get the front matter for that " . | ||||||||||||||||||||||||||||
| 519 | "document." ); | ||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 0 | return( $self->{ "front" }->{ $self->{ "active" } } ); | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 526 | ## getHeader ## | ||||||||||||||||||||||||||||
| 527 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 528 | sub getHeader | ||||||||||||||||||||||||||||
| 529 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getHeader: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 530 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 0 | return( $self->{ "header" } ); | |||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 536 | ## getText ## | ||||||||||||||||||||||||||||
| 537 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 538 | sub getText | ||||||||||||||||||||||||||||
| 539 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getText: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 540 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | ## Do some basic error checking ... | ||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||
| 545 | 0 | croak( "TEI composite and unitary documents are the only document " . | |||||||||||||||||||||||||||
| 546 | "types of the TEI specification that contain texts." ); | ||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | ## Declare a variable to hold our results. | ||||||||||||||||||||||||||||
| 550 | 0 | my @texts; | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 0 | return( $self->{ "text" }->{ $self->{ "active" } } ); | |||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 556 | ## getTexts ## | ||||||||||||||||||||||||||||
| 557 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 558 | sub getTexts | ||||||||||||||||||||||||||||
| 559 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getTexts: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 560 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | ## Do some basic error checking ... | ||||||||||||||||||||||||||||
| 563 | 0 | ▶ | if( $self->{ "Corpus" } != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 564 | { | ||||||||||||||||||||||||||||
| 565 | 0 | croak( "TEI composite and unitary documents are the only document " . | |||||||||||||||||||||||||||
| 566 | "types of the TEI specification that contain texts." ); | ||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | ## Declare a variable to hold our results. | ||||||||||||||||||||||||||||
| 570 | 0 | my @texts; | |||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | ## Loop through each of the texts and return a reference to | ||||||||||||||||||||||||||||
| 573 | ## that document. | ||||||||||||||||||||||||||||
| 574 | 0 | foreach( keys( %{ $self->{ "text" } } ) ) | |||||||||||||||||||||||||||
| 575 | { | ||||||||||||||||||||||||||||
| 576 | 0 | push( @texts, $self->{ "text" }->{ $_ } ); | |||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | ## If we call ourselves in a scalar context, return the | ||||||||||||||||||||||||||||
| 580 | ## number of corpus texts. | ||||||||||||||||||||||||||||
| 581 | 0 | ▶ | return( wantarray ? @texts : scalar( @texts ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 585 | ## setActiveDocument ## | ||||||||||||||||||||||||||||
| 586 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 587 | sub setActiveDocument | ||||||||||||||||||||||||||||
| 588 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
setActiveDocument: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 589 | 0 | my( $self, $active ) = @_; | |||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | ## If the passed in $active modifier is not a number, | ||||||||||||||||||||||||||||
| 592 | ## then that is obviously an error. | ||||||||||||||||||||||||||||
| 593 | 0 | ▶ | if( $active !~ /^\d+$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 594 | { | ||||||||||||||||||||||||||||
| 595 | 0 | croak( "The specified active document must be in numeric form." ); | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | ## Corpus texts do not have active documents as they | ||||||||||||||||||||||||||||
| 599 | ## are viewed as Document object containing more | ||||||||||||||||||||||||||||
| 600 | ## document objects. | ||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if( $self->{ "Corpus" } == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | { | ||||||||||||||||||||||||||||
| 603 | 0 | croak( "TEI corpus documents are the only document type containing " . | |||||||||||||||||||||||||||
| 604 | "other TEI documents." ); | ||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | ## If our $active text is greater then the number of | ||||||||||||||||||||||||||||
| 608 | ## texts in our composite document, then that is | ||||||||||||||||||||||||||||
| 609 | ## obviously an error. | ||||||||||||||||||||||||||||
| 610 | 0 | ▶ | if( $self->{ "Corpus" } < $active ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 611 | { | ||||||||||||||||||||||||||||
| 612 | 0 | croak( "The specified active document does not exist in this TEI " . | |||||||||||||||||||||||||||
| 613 | "corpus document." ); | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | ## Set the instance variable ... | ||||||||||||||||||||||||||||
| 617 | 0 | $self->{ "active" } = $active; | |||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 0 | return( $self->{ "active" } ); | |||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 623 | ## setActiveText ## | ||||||||||||||||||||||||||||
| 624 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 625 | sub setActiveText | ||||||||||||||||||||||||||||
| 626 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
setActiveText: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 627 | 0 | my( $self, $active ) = @_; | |||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | ## If the passed in $active modifier is not a number, | ||||||||||||||||||||||||||||
| 630 | ## then that is obviously an error. | ||||||||||||||||||||||||||||
| 631 | 0 | ▶ | if( $active !~ /^\d+$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 632 | { | ||||||||||||||||||||||||||||
| 633 | 0 | croak( "The specified active text must be in numeric form." ); | |||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | ## Corpus texts do not have active documents as they | ||||||||||||||||||||||||||||
| 637 | ## are viewed as Document object containing more | ||||||||||||||||||||||||||||
| 638 | ## document objects. | ||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if( $self->{ "Corpus" } > 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 640 | { | ||||||||||||||||||||||||||||
| 641 | 0 | croak( "TEI composite and unitary documents are the only document " . | |||||||||||||||||||||||||||
| 642 | "types containing other texts." ); | ||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | ## If our $active text is greater then the number of | ||||||||||||||||||||||||||||
| 646 | ## texts in our composite document, then that is | ||||||||||||||||||||||||||||
| 647 | ## obviously an error. | ||||||||||||||||||||||||||||
| 648 | 0 | ▶ | if( $self->{ "Composite" } < $active ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 649 | { | ||||||||||||||||||||||||||||
| 650 | 0 | croak( "The specified active text does not exist in this " . | |||||||||||||||||||||||||||
| 651 | "TEI document." ); | ||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | ## Set the instance variable ... | ||||||||||||||||||||||||||||
| 655 | 0 | $self->{ "active" } = $active; | |||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | 0 | return( $self->{ "active" } ); | |||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 661 | ## setDocumentLang ## | ||||||||||||||||||||||||||||
| 662 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 663 | sub setDocumentLang | ||||||||||||||||||||||||||||
| 664 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
setDocumentLang: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 665 | 0 | my( $self, $lang ) = @_; | |||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | 0 | ▶ | if( is_language_tag( $lang ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 668 | { | ||||||||||||||||||||||||||||
| 669 | 0 | $self->{ "DOM" }->documentElement->setAttribute( "lang", $lang ); | |||||||||||||||||||||||||||
| 670 | 0 | return( 1 ); | |||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | 0 | return( 0 ); | |||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | ##==================================================================## | ||||||||||||||||||||||||||||
| 677 | ## Internal Function(s) ## | ||||||||||||||||||||||||||||
| 678 | ##==================================================================## | ||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||
| 680 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 681 | ## _init_object_instance ## | ||||||||||||||||||||||||||||
| 682 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 683 | ## Internal function to initialize the object ## | ||||||||||||||||||||||||||||
| 684 | ## instance. ## | ||||||||||||||||||||||||||||
| 685 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 686 | sub _init_object_instance | ||||||||||||||||||||||||||||
| 687 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init_object_instance: called CC=10 SCAR=30.8
| |||||||||||||||||||||||||||||
| 688 | ## Pull in the parameters ... | ||||||||||||||||||||||||||||
| 689 | 2 | my %params = @_; | |||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | ## Create an anonymous hash to hold the basis of our object. | ||||||||||||||||||||||||||||
| 692 | 2 | my $self = {}; | |||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | ## We also define some variables that we will fill in later. | ||||||||||||||||||||||||||||
| 695 | 2 | my( $root_node ); | |||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | ## We need to clean up our two main augmentation parameters. | ||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | ## Clean up the Corpus modifier ... | ||||||||||||||||||||||||||||
| 700 | ## Corpus: 0 == false, # > 0 = Number of combined texts | ||||||||||||||||||||||||||||
| 701 | 2 | ▶ | if( defined( $params{ "Corpus" } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 702 | { | ||||||||||||||||||||||||||||
| 703 | 2 | ▶ | $params{ "Corpus" } = 0 if( $params{ "Corpus" } < 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||
| 705 | else | ||||||||||||||||||||||||||||
| 706 | { | ||||||||||||||||||||||||||||
| 707 | 0 | $params{ "Corpus" } = 0; | |||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | ## Stick it in our hash object. | ||||||||||||||||||||||||||||
| 711 | 2 | $self->{ "Corpus" } = $params{ "Corpus" }; | |||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | ## Clean up the Composite modifier ... | ||||||||||||||||||||||||||||
| 714 | ## Composite: 0 == false, # > 0 = Number of group "segments" | ||||||||||||||||||||||||||||
| 715 | 2 | ▶ | if( defined( $params{ "Composite" } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 716 | { | ||||||||||||||||||||||||||||
| 717 | 2 | ▶ | $params{ "Composite" } = 0 if( $params{ "Composite" } < 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||
| 719 | else | ||||||||||||||||||||||||||||
| 720 | { | ||||||||||||||||||||||||||||
| 721 | 0 | $params{ "Composite" } = 0; | |||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | ## Stick it in our hash object. | ||||||||||||||||||||||||||||
| 725 | 2 | $self->{ "Composite" } = $params{ "Composite" }; | |||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | ## Begin the construction of our internal DOM tree ... | ||||||||||||||||||||||||||||
| 728 | 2 | $self->{ "DOM" } = XML::LibXML::Document->new( "1.0", "UTF8" ); | |||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | 2 | ▶ | if( $params{ "Corpus" } > 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 731 | { | ||||||||||||||||||||||||||||
| 732 | 0 | $root_node = XML::LibXML::Element->new( "teiCorpus.2" ); | |||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||
| 734 | else | ||||||||||||||||||||||||||||
| 735 | { | ||||||||||||||||||||||||||||
| 736 | 2 | $root_node = XML::LibXML::Element->new( "TEI.2" ); | |||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | ## Make the $root_node the real root node. | ||||||||||||||||||||||||||||
| 740 | 2 | $self->{ "DOM" }->setDocumentElement( $root_node ); | |||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | ## Now we need to setup the rest of the basic document based on the | ||||||||||||||||||||||||||||
| 743 | ## given parameters. | ||||||||||||||||||||||||||||
| 744 | 2 | ▶ | if( $params{ "Corpus" } > 0 ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 745 | { | ||||||||||||||||||||||||||||
| 746 | ## TEI Corpus Document | ||||||||||||||||||||||||||||
| 747 | 0 | ▶ | foreach( my $loop = 0; $loop < $params{ "Corpus" }; $loop++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 748 | { | ||||||||||||||||||||||||||||
| 749 | 0 | $self->{ "document" }->{ $loop } = TEI::Lite::Document->new(); | |||||||||||||||||||||||||||
| 750 | $root_node->appendChild( | ||||||||||||||||||||||||||||
| 751 | 0 | $self->{ "document" }->{ $loop }->documentElement() ); | |||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||
| 755 | elsif( $params{ "Composite" } > 0 ) | ||||||||||||||||||||||||||||
| 756 | { | ||||||||||||||||||||||||||||
| 757 | 0 | my $text = tei_text(); | |||||||||||||||||||||||||||
| 758 | 0 | my $group = tei_group(); | |||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||
| 760 | 0 | ▶ | foreach( my $loop = 0; $loop < $params{ "Composite" }; $loop++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 761 | { | ||||||||||||||||||||||||||||
| 762 | 0 | $self->{ "text" }->{ $loop } = tei_text(); | |||||||||||||||||||||||||||
| 763 | 0 | $self->{ "body" }->{ $loop } = tei_body(); | |||||||||||||||||||||||||||
| 764 | $self->{ "text" }->{ $loop }-> | ||||||||||||||||||||||||||||
| 765 | 0 | appendChild( $self->{ "body" }->{ $loop } ); | |||||||||||||||||||||||||||
| 766 | 0 | $group->appendChild( $self->{ "text" }->{ $loop } ); | |||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | 0 | $root_node->appendChild( $text ); | |||||||||||||||||||||||||||
| 770 | 0 | $text->appendChild( $group ); | |||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||
| 772 | else | ||||||||||||||||||||||||||||
| 773 | { | ||||||||||||||||||||||||||||
| 774 | ## TEI Unitary Document | ||||||||||||||||||||||||||||
| 775 | 2 | $self->{ "text" }->{ "0" } = tei_text(); | |||||||||||||||||||||||||||
| 776 | 2 | $self->{ "body" }->{ "0" } = tei_body(); | |||||||||||||||||||||||||||
| 777 | 2 | $self->{ "text" }->{ "0" }->appendChild( $self->{ "body" }->{ "0" } ); | |||||||||||||||||||||||||||
| 778 | 2 | $root_node->appendChild( $self->{ "text" }->{ "0" } ); | |||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||
| 781 | ## Setup a default text to be active ... as in all operations by | ||||||||||||||||||||||||||||
| 782 | ## default act upon this text. | ||||||||||||||||||||||||||||
| 783 | 2 | $self->{ "active" } = 0; | |||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | ## Return what we have constructed. | ||||||||||||||||||||||||||||
| 786 | 2 | return( $self ); | |||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||
| 789 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 790 | ## _load_teilite_file ## | ||||||||||||||||||||||||||||
| 791 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 792 | ## Attempts to load a document that is in the ## | ||||||||||||||||||||||||||||
| 793 | ## TEILite schema format. ## | ||||||||||||||||||||||||||||
| 794 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 795 | sub _load_teilite_file | ||||||||||||||||||||||||||||
| 796 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_load_teilite_file: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 797 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||
| 799 | ## We need a variable to hold our instance variable. | ||||||||||||||||||||||||||||
| 800 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | ## Create an instance of the LibXML parser to load the file. | ||||||||||||||||||||||||||||
| 803 | 0 | my $parser = XML::LibXML->new(); | |||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||
| 805 | ## Attempt to load the file. | ||||||||||||||||||||||||||||
| 806 | 0 | my $doc = $parser->parse_file( $params{ 'Filename' } ); | |||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | ## Grab the document element ... | ||||||||||||||||||||||||||||
| 809 | 0 | my $root = $doc->getDocumentElement(); | |||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||
| 811 | ## Determine whaat type of document we are working with now. | ||||||||||||||||||||||||||||
| 812 | 0 | ▶ | if( $root->nodeName eq "teiCorpus.2" ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 813 | { | ||||||||||||||||||||||||||||
| 814 | 0 | $self = _parse_teicorpus_document( $doc ); | |||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||
| 816 | elsif( $root->nodeName eq "TEI.2" ) | ||||||||||||||||||||||||||||
| 817 | { | ||||||||||||||||||||||||||||
| 818 | 0 | $self = _parse_tei_document( $doc ); | |||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||
| 820 | else | ||||||||||||||||||||||||||||
| 821 | { | ||||||||||||||||||||||||||||
| 822 | 0 | croak( "The specified file is not a recognized TEILite document.\n" ); | |||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||
| 825 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||
| 828 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 829 | ## _load_teilite_string ## | ||||||||||||||||||||||||||||
| 830 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 831 | ## Attempts to load a document that is in the ## | ||||||||||||||||||||||||||||
| 832 | ## TEILite schema format. ## | ||||||||||||||||||||||||||||
| 833 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 834 | sub _load_teilite_string | ||||||||||||||||||||||||||||
| 835 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_load_teilite_string: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 836 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||
| 838 | ## We need a variable to hold our instance variable. | ||||||||||||||||||||||||||||
| 839 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | ## Create an instance of the LibXML parser to load the file. | ||||||||||||||||||||||||||||
| 842 | 0 | my $parser = XML::LibXML->new(); | |||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | ## Attempt to load the file. | ||||||||||||||||||||||||||||
| 845 | 0 | my $doc = $parser->parse_string( $params{ 'String' } ); | |||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||
| 847 | ## Grab the document element ... | ||||||||||||||||||||||||||||
| 848 | 0 | my $root = $doc->getDocumentElement(); | |||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | ## Determine whaat type of document we are working with now. | ||||||||||||||||||||||||||||
| 851 | 0 | ▶ | if( $root->nodeName eq "teiCorpus.2" ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 852 | { | ||||||||||||||||||||||||||||
| 853 | 0 | $self = _parse_teicorpus_document( $doc ); | |||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||
| 855 | elsif( $root->nodeName eq "TEI.2" ) | ||||||||||||||||||||||||||||
| 856 | { | ||||||||||||||||||||||||||||
| 857 | 0 | $self = _parse_tei_document( $doc ); | |||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||
| 859 | else | ||||||||||||||||||||||||||||
| 860 | { | ||||||||||||||||||||||||||||
| 861 | 0 | croak( "The specified file is not a recognized TEILite document.\n" ); | |||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||
| 864 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||
| 867 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 868 | ## _parse_tei_document ## | ||||||||||||||||||||||||||||
| 869 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 870 | ## Function to break-apart a TEILite document ## | ||||||||||||||||||||||||||||
| 871 | ## into the instance variable structure. ## | ||||||||||||||||||||||||||||
| 872 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 873 | sub _parse_tei_document | ||||||||||||||||||||||||||||
| 874 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_parse_tei_document: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 875 | 0 | my $doc = shift; | |||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | ## We use an anonymous hash as our internal structure. | ||||||||||||||||||||||||||||
| 878 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||
| 880 | ## Grab the root element of the document. | ||||||||||||||||||||||||||||
| 881 | 0 | my $root = $doc->getDocumentElement(); | |||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | ## We set the entire DOM tree into the DOM key. | ||||||||||||||||||||||||||||
| 884 | 0 | $self->{ "DOM" } = $doc; | |||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||
| 886 | ## We are not a corpus document. | ||||||||||||||||||||||||||||
| 887 | 0 | $self->{ "Corpus" } = 0; | |||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | ## We now need to determine if we are a composite or unitary document. | ||||||||||||||||||||||||||||
| 890 | 0 | my( @texts ) = $root->findnodes( "//text" ); | |||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||
| 892 | ## Loop through each of the texts loading them into our internal struct. | ||||||||||||||||||||||||||||
| 893 | 0 | ▶ | for( my $i = 0; $i < scalar( @texts ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 894 | { | ||||||||||||||||||||||||||||
| 895 | ## Set the Composite document counter. | ||||||||||||||||||||||||||||
| 896 | 0 | $self->{ "Composite" } = $i; | |||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | ## Set the base "text" element. | ||||||||||||||||||||||||||||
| 899 | 0 | $self->{ "text" }->{ $i } = $texts[ $i ]; | |||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | ## Grab the children of the text element. | ||||||||||||||||||||||||||||
| 902 | 0 | my( @children ) = $texts[ $i ]->childNodes; | |||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | 0 | foreach( @children ) | |||||||||||||||||||||||||||
| 905 | { | ||||||||||||||||||||||||||||
| 906 | 0 | ▶ | if( $_->nodeName eq "front" ) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 907 | { | ||||||||||||||||||||||||||||
| 908 | 0 | $self->{ "front" }->{ $i } = $_; | |||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||
| 910 | elsif( $_->nodeName eq "body" ) | ||||||||||||||||||||||||||||
| 911 | { | ||||||||||||||||||||||||||||
| 912 | 0 | $self->{ "body" }->{ $i } = $_; | |||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||
| 914 | elsif( $_->nodeName eq "back" ) | ||||||||||||||||||||||||||||
| 915 | { | ||||||||||||||||||||||||||||
| 916 | 0 | $self->{ "back" }->{ $i } = $_; | |||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||
| 921 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||
| 924 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 925 | ## _parse_teicorpus_document ## | ||||||||||||||||||||||||||||
| 926 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 927 | ## Function to break-apart a TEILite document ## | ||||||||||||||||||||||||||||
| 928 | ## into the instance variable structure. ## | ||||||||||||||||||||||||||||
| 929 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 930 | sub _parse_teicorpus_document | ||||||||||||||||||||||||||||
| 931 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_parse_teicorpus_document: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 932 | 0 | my $doc = shift; | |||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||
| 934 | ## We use an anonymous hash as our internal structure. | ||||||||||||||||||||||||||||
| 935 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | ## We set the entire DOM tree into the DOM key. | ||||||||||||||||||||||||||||
| 938 | 0 | $self->{ "DOM" } = XML::LibXML::Document->new(); | |||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||
| 940 | 0 | my $root = XML::LibXML::Element->new( "teiCorpus.2" ); | |||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | 0 | $self->{ "DOM" }->setDocumentElement( $root ); | |||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||
| 944 | ## We are not a composite document. | ||||||||||||||||||||||||||||
| 945 | 0 | $self->{ "Composite" } = 0; | |||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||
| 947 | ## We now need to determine if we are a composite or unitary document. | ||||||||||||||||||||||||||||
| 948 | 0 | my( @texts ) = $doc->getDocumentElement()->findnodes( "//TEI.2" ); | |||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||
| 950 | ## Loop through each of the texts loading them into our internal struct. | ||||||||||||||||||||||||||||
| 951 | 0 | ▶ | for( my $i = 0; $i < scalar( @texts ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 952 | { | ||||||||||||||||||||||||||||
| 953 | ## Set the Composite document counter. | ||||||||||||||||||||||||||||
| 954 | 0 | $self->{ "Corpus" } = $i; | |||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | ## Set the base "text" element. | ||||||||||||||||||||||||||||
| 957 | 0 | $self->{ "document" }->{ $i } = | |||||||||||||||||||||||||||
| 958 | TEI::Lite::Document->new( String => $_->toString() ); | ||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||
| 960 | 0 | $root->appendChild( $self->{ "document" }->{ $i }->documentElement ); | |||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||
| 963 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||
| 966 | ##==================================================================## | ||||||||||||||||||||||||||||
| 967 | ## End of Code ## | ||||||||||||||||||||||||||||
| 968 | ##==================================================================## | ||||||||||||||||||||||||||||
| 969 | 6 | 1; | |||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||
| 971 | ##==================================================================## | ||||||||||||||||||||||||||||
| 972 | ## Plain Old Documentation (POD) ## | ||||||||||||||||||||||||||||
| 973 | ##==================================================================## | ||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||
| 975 | __END__ | ||||||||||||||||||||||||||||