| 1 | # | ||||||||||||||
| 2 | # This file is part of Docbook::Convert. | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 8 | # | ||||||||||||||
| 9 | # Full license text is available at: | ||||||||||||||
| 10 | # | ||||||||||||||
| 11 | # <http://dev.perl.org/licenses/> | ||||||||||||||
| 12 | # | ||||||||||||||
| 13 | |||||||||||||||
| 14 | # | ||||||||||||||
| 15 | # | ||||||||||||||
| 16 | package Docbook::Convert::Util; | ||||||||||||||
| 17 | |||||||||||||||
| 18 | |||||||||||||||
| 19 | # Pragma | ||||||||||||||
| 20 | # | ||||||||||||||
| 21 | 4 | ▶ | use strict qw(vars); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 4 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 4 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | 4 | ▶ | no warnings qw(uninitialized); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | |||||||||||||||
| 27 | # Constants | ||||||||||||||
| 28 | # | ||||||||||||||
| 29 | 4 | ▶ | use Docbook::Convert::Constant; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 30 | |||||||||||||||
| 31 | |||||||||||||||
| 32 | # External modules | ||||||||||||||
| 33 | # | ||||||||||||||
| 34 | 4 | require Exporter; | |||||||||||||
| 35 | 4 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | |||||||||||||||
| 38 | # Export functions | ||||||||||||||
| 39 | # | ||||||||||||||
| 40 | 4 | @ISA=qw(Exporter); | |||||||||||||
| 41 | 4 | @EXPORT=qw(err msg debug dump_ar whitespace_clean); | |||||||||||||
| 42 | |||||||||||||||
| 43 | |||||||||||||||
| 44 | # Version information in a format suitable for CPAN etc. Must be | ||||||||||||||
| 45 | # all on one line | ||||||||||||||
| 46 | # | ||||||||||||||
| 47 | 4 | $VERSION='1.012'; | |||||||||||||
| 48 | |||||||||||||||
| 49 | |||||||||||||||
| 50 | # All done, init finished | ||||||||||||||
| 51 | # | ||||||||||||||
| 52 | 4 | 1; | |||||||||||||
| 53 | |||||||||||||||
| 54 | |||||||||||||||
| 55 | #=================================================================================================== | ||||||||||||||
| 56 | |||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | sub dump_ar { | ||||||||||||
|
Subroutine
dump_ar: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | my $data_ar=shift(); | |||||||||||||
| 61 | 0 | ▶ | my $cr=sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||
| 62 | 0 | my ($cr, $data_ar)=@_; | |||||||||||||
| 63 | 0 | ▶ | if ($data_ar->[$NODE_IX] eq 'text') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 0 | foreach my $ix (0..@{$data_ar->[$PRNT_IX][$CHLD_IX]}) { | |||||||||||||
| 65 | 0 | ▶ | if ($data_ar->[$PRNT_IX][$CHLD_IX][$ix] eq $data_ar) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | 0 | $data_ar->[$PRNT_IX][$CHLD_IX][$ix]=$data_ar->[$CHLD_IX][0]; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | } | ||||||||||||||
| 69 | } | ||||||||||||||
| 70 | 0 | foreach my $ar (@{$data_ar->[$CHLD_IX]}) { | |||||||||||||
| 71 | 0 | ▶ | if (ref($ar)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 0 | $cr->($cr, $ar); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | 0 | $data_ar->[$PRNT_IX]=$data_ar->[$PRNT_IX][$NODE_IX]; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | }; | |||||||||||||
| 78 | 0 | $cr->($cr, $data_ar); | |||||||||||||
| 79 | 0 | return $data_ar; | |||||||||||||
| 80 | |||||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | ▶ | sub whitespace_clean { | ||||||||||||
|
Subroutine
whitespace_clean: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | my $text=shift(); | |||||||||||||
| 87 | 0 | debug("whitespace_clean *$text*"); | |||||||||||||
| 88 | 0 | $text=~s/^\t//gm; | |||||||||||||
| 89 | 0 | my @para; | |||||||||||||
| 90 | 0 | my @text=($text=~/^(.*)$/gm); | |||||||||||||
| 91 | 0 | foreach my $line (@text) { | |||||||||||||
| 92 | 0 | ▶ | if ($line=~/^\s+\S+/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 93 | 0 | $line=~s/^\s+/ /; | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | elsif ($line=~/^\s*$/) { | ||||||||||||||
| 96 | 0 | next; | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | 0 | push @para, $line | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | 0 | my $para=join($CR, @para); | |||||||||||||
| 101 | |||||||||||||||
| 102 | #my $para=join($SP, @para, $SP); | ||||||||||||||
| 103 | 0 | $para=~s/\s{2,}/ /; | |||||||||||||
| 104 | |||||||||||||||
| 105 | #$para=~s/^\s+//; | ||||||||||||||
| 106 | #$para=~s/\s*$//; | ||||||||||||||
| 107 | 0 | return $para; | |||||||||||||
| 108 | |||||||||||||||
| 109 | } | ||||||||||||||
| 110 | |||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | ▶ | sub err { | ||||||||||||
|
Subroutine
err: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 113 | |||||||||||||||
| 114 | |||||||||||||||
| 115 | # Quit on errors | ||||||||||||||
| 116 | # | ||||||||||||||
| 117 | 0 | my $msg=shift(); | |||||||||||||
| 118 | 0 | my $err=&fmt("*error*\n\n" . ucfirst($msg), @_); | |||||||||||||
| 119 | 0 | ▶ | return $ERR_BACKTRACE ? confess $err : croak $err; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 120 | |||||||||||||||
| 121 | } | ||||||||||||||
| 122 | |||||||||||||||
| 123 | |||||||||||||||
| 124 | 0 | ▶ | sub fmt { | ||||||||||||
|
Subroutine
fmt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 125 | |||||||||||||||
| 126 | |||||||||||||||
| 127 | # Format message nicely. Always called by err or msg so caller=2 | ||||||||||||||
| 128 | # | ||||||||||||||
| 129 | 0 | my $message=sprintf(shift(), @_); | |||||||||||||
| 130 | 0 | chomp($message); | |||||||||||||
| 131 | 0 | my $caller=(split(/:/, (caller(2))[3]))[-1]; | |||||||||||||
| 132 | 0 | $caller=~s/^_?!(_)//; | |||||||||||||
| 133 | 0 | my $format=' @<<<<<<<<<<<<<<<<<<<<<< @<'; | |||||||||||||
| 134 | 0 | formline $format, $caller . ':', undef; | |||||||||||||
| 135 | 0 | $message=$^A . $message; $^A=undef; | |||||||||||||
| 136 | 0 | return $message; | |||||||||||||
| 137 | |||||||||||||||
| 138 | } | ||||||||||||||
| 139 | |||||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | ▶ | sub msg { | ||||||||||||
|
Subroutine
msg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 142 | |||||||||||||||
| 143 | |||||||||||||||
| 144 | # Print message | ||||||||||||||
| 145 | # | ||||||||||||||
| 146 | 0 | ▶ | CORE::print &fmt(@_), "\n" if $VERBOSE; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 147 | |||||||||||||||
| 148 | } | ||||||||||||||
| 149 | |||||||||||||||
| 150 | |||||||||||||||
| 151 | 0 | ▶ | sub debug { | ||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 152 | 0 | ▶ | CORE::print STDERR &fmt(@_), "\n" if $DEBUG; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | __END__ | ||||||||||||||