blib/lib/oEdtk/Utils.pm

filter: Statementstmt 31.2% 54 / 173 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 34.1% 14 / 41 Podpod 51.8% 14 / 27 totaltotal 25.0% 82 / 327 CC 40 SCAR 31.0
CC
40
Cov
22%
comment_index_file
90.0
scalar_dump
42.0
latest_idx1_in_directory
42.0
CRAP 22.2
« blib/lib/oEdtk/TexTag.pm ↑ Summary blib/lib/oEdtk/Messenger.pm »
1 package oEdtk::Utils;
2  
3 # Generic utilities (docs/integration/PLAN.md, S23). The fork's
4 # oEdtk::Utils mixed generic helpers with corporate ones; this module keeps the
5 # generic part only (text cleanup, index format, date and price parsing,
6 # tracking helpers, small value helpers) and is free of any corporate
7 # reference. The corporate part -- init() and the INDEX_* accessors, which call
8 # oEUser::Lib or name corporate schema identifiers -- lives in oEUser::Utils;
9 # the old names stay available here as delegates. oEUser is an optional
10 # companion distribution: it is loaded on demand, and a missing one fails
11 # cleanly rather than breaking the oEdtk load.
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # The fork's own test imported delete_useless_whitespaces, but the fork left it
22 # out of @EXPORT_OK (a latent Exporter error). Both generic text helpers are
23 # exported here; the fork's remaining exported names are kept unchanged.
24 2 our @EXPORT_OK = qw(
25 delete_useless_whitespaces IDX_FORMAT kill_non_latin_1_9_chars_in_place
26 alert flatten_index_variables max_value parse_jjmmaaaa parse_price
27 parse_yyyymmdd scalar_dump track track_begin track_end trim_list
28 );
29  
30 2 our $VERSION = 2.1126;
31  
32 2 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Date::Calc qw(Days_in_Month);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use Regexp::Common qw(whitespace);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use Term::ANSIColor qw(colored);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use Text::CSV_XS qw(csv);
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 # The LaTeX index format: pairs of "old LaTeX tag" => "new index field", with
42 # an optional list offset. The first four fields are only known to LaTeX and
43 # are therefore skipped by the generic table (see the fork's edtkdoc.cls).
44 2 Readonly my $LATEX_INDEX_FORMAT => [
45 [ xAppRef => 'applicationReference' ],
46 [ xIdLdoc => 'idLotDocuments' ],
47 [ thepage => 'pageNumber' ],
48 [ thedoc => 'docNumber' ],
49 ];
50  
51 2 Readonly my $INDEX_FORMAT => [
52 [ xCPDEST => 'indexDestCodePostal' ],
53 [ xVILDEST => 'indexDestVille' ],
54 [ xIDDEST => 'indexIdDest' ],
55 [ xNOMDEST => 'indexDestNomPrenom' ],
56 [ xIDEMET => 'indexIdEmetteur' ],
57 [ dtedition => 'date_edition' ],
58 [ xTYPPROD => 'type_production' ],
59 [ xPORTADR => '' ], # unused
60 [ daddr => 'adresse', 0 ],
61 [ xCLEGEDi => 'indexClef', 0 ],
62 [ daddri => 'adresse', 1 ],
63 [ xCLEGEDii => 'indexClef', 1 ],
64 [ daddrii => 'adresse', 2 ],
65 [ xCLEGEDiii => 'indexClef', 2 ],
66 [ daddriii => 'adresse', 3 ],
67 [ xCLEGEDiv => 'indexClef', 3 ],
68 [ daddriv => 'adresse', 4 ],
69 [ edCorp => 'corporation' ],
70 [ xDOCLIB => 'pdf_filename' ],
71 [ xREFIMP => 'ref_preimprime' ],
72 [ daddrv => 'adresse', 5 ],
73 [ xSOURCE => 'domaine_metier' ],
74 [ xOWNER => 'demandeur_edition' ],
75 [ xHOST => 'serveur_edition' ],
76 [ xIDIDX => 'version_idx' ],
77 [ xCATDOC => 'categorie_doc' ], # unused
78 [ xCODRUPT => 'code_rupture' ],
79 [ xTYPEDOC => 'type_document' ],
80 [ xCLEGEDv => 'indexClef', 4 ],
81 [ xIDPMSIR => 'id_pers_moral_siret' ],
82 ];
83  
84 2 Readonly my $FULL_INDEX_FORMAT => [ @{$LATEX_INDEX_FORMAT}, @{$INDEX_FORMAT} ];
85  
86 # French month names, as ASCII source (accents expressed with \x escapes).
87 2 Readonly my @FRENCH_MONTHS => (
88 "janvier", "f\x{e9}vrier", "mars", "avril", "mai", "juin",
89 "juillet", "ao\x{fb}t", "septembre", "octobre", "novembre", "d\x{e9}cembre",
90 );
91  
92 2 Readonly my $TRACK_MODE_BATCH => 'Batch';
93 2 Readonly my $TRACK_DOCUMENT => 'D';
94 2 Readonly my $TRACK_WARNING => 'W';
95 2 Readonly my $TRACK_END_MSG => 'Fin de traitement';
96  
97 # The document-type value used when the caller does not pass one.
98 2 Readonly my $SPACE => "\x20";
99  
100 # --- text cleanup ----------------------------------------------------------
101  
102 # Replace illegal latin-1/latin-9 bytes (0x7f..0x9f) with spaces, in place.
103 # Keeps C0 control characters; circumvents garbage sometimes received in flows.
104 0 ▶sub kill_non_latin_1_9_chars_in_place ($strRef) {
Subroutine kill_non_latin_1_9_chars_in_place: not called CC=1 SCAR=6.9
Pod documented
105 0 $$strRef =~ s/[\x7f\x80-\x9f]/$SPACE/gsox;
106 0 return;
107 }
108  
109 # Join a list with single spaces, collapsing runs of whitespace.
110 0 ▶sub trim_list (@l) {
Subroutine trim_list: not called CC=1 SCAR=6.9
Pod documented
111 0 my $str = join( $SPACE, @l );
112 0 $str =~ s{^\s+}{}sx;
113 0 $str =~ s{\s+\@}{}sox; # kept verbatim from the fork
114 0 $str =~ s/\s+/$SPACE/gsox;
115 0 return $str;
116 }
117  
118 # Remove surrounding whitespace and collapse internal runs to one space.
119 0 ▶sub delete_useless_whitespaces ($str) {
Subroutine delete_useless_whitespaces: not called CC=2 SCAR=17.9
Pod documented
120 0 ▶ croak 'str undef' if !defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
121 0 $str = $RE{ws}{crop}->subs($str); # delete surrounding whitespace
122 0 $str =~ s/\s+/\x20/gsxm; # delete useless whitespace
123 0 return $str;
124 }
125  
126 # --- index format ----------------------------------------------------------
127  
128 # The current index format, as an arrayref of [ old_tag, new_field, offset ].
129 1 ▶sub IDX_FORMAT () {
Subroutine IDX_FORMAT: called CC=1 SCAR=0.0
Pod documented
130 1 return $INDEX_FORMAT;
131 }
132  
133 # --- date parsing ----------------------------------------------------------
134  
135 # Return a non-empty error message when (year, month, day) is not a valid date.
136 0 ▶sub check_date ( $year, $mon, $dd, $str ) {
Subroutine check_date: not called CC=5 SCAR=34.0
Pod undocumented
137 0 ▶ return "bad month number for date '$str'" if $mon < 1 || $mon > 12;
Branch: 1 branch
BranchTrueFalseTotal
if $mon < 1 or $mon > 12 0 0 0
Condition0%0/3
$mon < 1 or $mon > 12
l!l&&r!l&&!r
000
MC/DC0%0/2
$mon < 1 or $mon > 12
$mon < 1 $mon > 12
Truth table0%0/3
A or B
A= $mon < 1B= $mon > 12
ABresult
1X1
011
000
138 0 ▶ return "bad day number for date '$str'"
Branch: 1 branch
BranchTrueFalseTotal
if $dd < 1 or $dd > Days_in_Month($year, $mon) 0 0 0
Condition0%0/3
$dd < 1 or $dd > Days_in_Month($year, $mon)
l!l&&r!l&&!r
000
MC/DC0%0/2
$dd < 1 or $dd > Days_in_Month($year, $mon)
$dd < 1 $dd > Days_in_Month($year, $mon)
Truth table0%0/3
A or B
A= $dd < 1B= $dd > Days_in_Month($year, $mon)
ABresult
1X1
011
000
139 if $dd < 1 || $dd > Days_in_Month( $year, $mon );
140 0 return '';
141 }
142  
143 # Return [ day, "month_name year" ] when the string is dd/mm/yyyy.
144 0 ▶sub parse_jjmmaaaa ( $str, $flowFile, $lineNumber ) {
Subroutine parse_jjmmaaaa: not called CC=3 SCAR=24.8
Pod documented
145 0 ▶ if ( $str =~ m{^ 0* (\d+) / 0*(\d+) / (\d+) $}sx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[^ 0* (\d+) / 0*(\d+) / (\d+) $]sx) 0 0 0
146 0 my ( $dd, $mon, $year ) = ( $1, $2, $3 );
147 0 my $error_msg = check_date( $year, $mon, $dd, $str );
148 0 ▶ return alert( $flowFile, $lineNumber, $error_msg, [$str] )
Branch: 1 branch
BranchTrueFalseTotal
if length $error_msg 0 0 0
149 if length $error_msg;
150 0 return [ $dd, "$FRENCH_MONTHS[$mon-1] $year" ];
151 }
152 0 return alert( $flowFile, $lineNumber, "cannot parse date '$str'", [$str] );
153 }
154  
155 # Return [ day, "month_name year" ] when the string is yyyymmdd.
156 0 ▶sub parse_yyyymmdd ( $str, $flowFile, $lineNumber ) {
Subroutine parse_yyyymmdd: not called CC=3 SCAR=24.8
Pod documented
157 0 ▶ if ( $str =~ m{^ (\d\d\d\d) (\d\d) (\d\d) $}sx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^ (\d\d\d\d) (\d\d) (\d\d) $/sx) 0 0 0
158 0 my ( $year, $mon, $dd ) = map { sprintf( '%d', $_ ) } ( $1, $2, $3 );
159 0 my $error_msg = check_date( $year, $mon, $dd, $str );
160 0 ▶ return alert( $flowFile, $lineNumber, $error_msg, [$str] )
Branch: 1 branch
BranchTrueFalseTotal
if length $error_msg 0 0 0
161 if length $error_msg;
162 0 return [ $dd, "$FRENCH_MONTHS[$mon-1] $year" ];
163 }
164 0 return alert( $flowFile, $lineNumber, "cannot parse date '$str'", [$str] );
165 }
166  
167 # Check that a price is valid; return it unchanged, else alert.
168 0 ▶sub parse_price ( $n, $flowFile, $lineNumber ) {
Subroutine parse_price: not called CC=3 SCAR=24.8
Pod documented
169 0 ▶ return $n if $n =~ m{^ [0-9]+(?:\.[0-9]+)? }sox || $n =~ m{^ \.[0-9]+ $}sox;
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /^ [0-9]+(?:\.[0-9]+)? /osx or $n =~ /^ \.[0-9]+ $/osx 0 0 0
Condition0%0/3
$n =~ /^ [0-9]+(?:\.[0-9]+)? /osx or $n =~ /^ \.[0-9]+ $/osx
l!l&&r!l&&!r
000
MC/DC0%0/2
$n =~ /^ [0-9]+(?:\.[0-9]+)? /osx or $n =~ /^ \.[0-9]+ $/osx
$n =~ /^ [0-9]+(?:\.[0-9]+)? /osx $n =~ /^ \.[0-9]+ $/osx
Truth table0%0/3
A or B
A= $n =~ /^ [0-9]+(?:\.[0-9]+)? /osxB= $n =~ /^ \.[0-9]+ $/osx
ABresult
1X1
011
000
170 0 return alert( $flowFile, $lineNumber, "cannot parse price '$n'", [$n] );
171 }
172  
173 # Conversion of a yyyymmdd date to dd/mm/yyyy.
174 0 ▶sub convert_date ($refvar) {
Subroutine convert_date: not called CC=2 SCAR=17.9
Pod undocumented
175 0 ▶ croak 'refvar undef' if !defined $refvar;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $refvar 0 0 0
176 0 $refvar =~ s/(\d{4})(\d{2})(\d{2})(.*)/$3\/$2\/$1/oxms;
177 0 return $refvar;
178 }
179  
180 # The capitalized month name for a 1-based month number (distinct from the
181 # lowercase @FRENCH_MONTHS used by the date parsers, as in the fork).
182 0 ▶sub month_to_name ($lib_month) {
Subroutine month_to_name: not called CC=2 SCAR=17.9
Pod undocumented
183 0 my @mons = (
184 "Janvier", "F\x{e9}vrier", "Mars", "Avril", "Mai", "Juin",
185 "Juillet", "Ao\x{fb}t", "Septembre", "Octobre", "Novembre", "D\x{e9}cembre",
186 );
187 0 ▶ $lib_month || croak 'lib_month undef';
Branch: 1 branch
BranchTrueFalseTotal
$lib_month or croak("lib_month undef") 0 0 0
188 0 return $mons[ $lib_month - 1 ];
189 }
190  
191 # --- helpers ---------------------------------------------------------------
192  
193 0 ▶sub my_dumper ($obj) {
Subroutine my_dumper: not called CC=1 SCAR=6.9
Pod undocumented
194 0 my $res = Dumper($obj);
195 0 $res =~ s{^\$VAR\d+ \s = \s }{}sx;
196 0 return $res;
197 }
198  
199 # Add an alert: carp with the flow file, the line number and the objects.
200 0 ▶sub alert ( $flowFile, $lineNumber, $msg, @objs ) {
Subroutine alert: not called CC=1 SCAR=6.9
Pod documented
201 0 carp "alert: flowFile='$flowFile' lineNumber='$lineNumber' msg='$msg' objs: "
202 . my_dumper( \@objs );
203 }
204  
205 # Return a hashref of the index_variables sub-hash, keys prefixed with "index".
206 0 ▶sub flatten_index_variables ($h) {
Subroutine flatten_index_variables: not called CC=2 SCAR=17.9
Pod documented
207 0 my $iv = $h->{'index_variables'};
208 0 my $index = {};
209 0 foreach my $key ( keys %{$iv} ) {
210 0 $index->{"index$key"} = $iv->{$key};
211 }
212 0 return $index;
213 }
214  
215 # The "max" value (string-wise) in a list.
216 0 ▶sub max_value ($l) {
Subroutine max_value: not called CC=3 SCAR=24.8
Pod documented
217 0 my $res = $$l[0];
218 0 foreach my $str ( @{$l} ) {
219 0 ▶ $res = $str if $str gt $res;
Branch: 1 branch
BranchTrueFalseTotal
if $str gt $res 0 0 0
220 }
221 0 return $res;
222 }
223  
224 # Return the special bytes of a scalar in an easier to read form.
225 0 ▶sub scalar_dump ($str) {
Subroutine scalar_dump: not called CC=6 SCAR=37.4
Pod documented
226 0 my @res = ();
227 0 my $n = length($str);
228 0 ▶ for ( my $i = 0 ; $i < $n ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 0 0 0
229 0 my $char = substr( $str, $i, 1 );
230 0 my $ord = ord($char);
231 0 ▶ if ( ( $ord >= 32 ) && ( $ord <= 126 ) && ( $ord != 28 ) && ( $ord != 29 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ord >= 32 and $ord <= 126 and $ord != 28 and $ord != 29) { } 0 0 0
Condition0%0/9
$ord >= 32 and $ord <= 126 and $ord != 28 and $ord != 29
!ll&&!rl&&r
000
$ord >= 32 and $ord <= 126 and $ord != 28
!ll&&!rl&&r
000
$ord >= 32 and $ord <= 126
!ll&&!rl&&r
000
MC/DC0%0/4
$ord >= 32 and $ord <= 126 and $ord != 28 and $ord != 29
$ord >= 32 $ord <= 126 $ord != 28 $ord != 29
Truth table0%0/5
A and B and C and D
A= $ord >= 32B= $ord <= 126C= $ord != 28D= $ord != 29
ABCDresult
0XXX0
10XX0
110X0
11100
11111
232 0 push @res, $char;
233 }
234 else {
235 0 push @res, sprintf( "(x%02x)", $ord );
236 }
237 }
238 0 return join( '', @res );
239 }
240  
241 # --- index file inspection (diagnostic helpers) ----------------------------
242  
243 # The latest .idx1 file in a directory.
244 0 ▶sub latest_idx1_in_directory ($dir) {
Subroutine latest_idx1_in_directory: not called CC=6 SCAR=37.4
Pod undocumented
245 0 ▶ opendir( my $dh, $dir ) || croak $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or croak($!) 0 0 0
246 0 my ( $latest_file, $latest_time ) = ( '', 0 );
247 0 ▶ while ( readdir $dh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readdir $dh)) 0 0 0
248 0 my $file = $_;
249 0 ▶ if ( $file =~ m{\.idx1$}sx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.idx1$/sx) 0 0 0
250 0 my $path = "$dir/$file";
251 0 my $ctime = ( stat($path) )[9];
252 0 ▶ ( $latest_file, $latest_time ) = ( $path, $ctime ) if $ctime > $latest_time;
Branch: 1 branch
BranchTrueFalseTotal
if $ctime > $latest_time 0 0 0
253 }
254 }
255 0 closedir $dh;
256 0 ▶ croak "No file found in '$dir'" unless length $latest_file;
Branch: 1 branch
BranchTrueFalseTotal
unless length $latest_file 0 0 0
257 0 return $latest_file;
258 }
259  
260 # Print the columns of an index file, in a readable form.
261 0 ▶sub comment_index_file ($file) {
Subroutine comment_index_file: not called CC=9 SCAR=45.0
Pod undocumented
262 0 ▶ $file = '.' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
263 0 ▶ $file = latest_idx1_in_directory($file) if -d $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 0 0 0
264 0 my $aoa = csv( in => $file, sep_char => ';' );
265 0 ▶ croak "Problem parsing CSV from '$file': $!" unless defined $aoa;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $aoa 0 0 0
266 0 my $nCols = scalar @{$FULL_INDEX_FORMAT};
267 0 my $nRows = scalar @{$aoa};
268 0 ▶ for ( my $i = 0 ; $i < $nRows ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nRows) 0 0 0
269 0 my $ii = $i + 1;
270 0 my $row = $$aoa[$i];
271 0 my $ncols = scalar @{$row};
272 0 ▶ carp "Found $ncols columns on row $ii; expected $nCols"
Branch: 1 branch
BranchTrueFalseTotal
if $ncols != $nCols 0 0 0
273 if $ncols != $nCols;
274 0 print "\nROW $ii/$nRows\n";
275 0 ▶ for ( my $j = 0 ; $j < $nCols ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $nCols) 0 0 0
276 0 my $jj = $j + 1;
277 0 my $value = $$row[$j];
278 0 ▶ $value = '(undef)' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
279 0 my ( $old_field, $new_field, $index ) = @{ $$FULL_INDEX_FORMAT[$j] };
280 0 ▶ $new_field .= "[$index]" if defined $index;
Branch: 1 branch
BranchTrueFalseTotal
if defined $index 0 0 0
281 0 print "COL $jj/$nCols: $old_field / $new_field: ", colored( $value, 'bold red' ), "\n";
282 }
283 }
284 0 return;
285 }
286  
287 # --- tracking --------------------------------------------------------------
288  
289 # Return a constant.
290 0 ▶sub TRACK_MODE_BATCH () {
Subroutine TRACK_MODE_BATCH: not called CC=1 SCAR=6.9
Pod undocumented
291 0 return $TRACK_MODE_BATCH;
292 }
293  
294 # Start tracking; return a tracking object. The tracking class (and the main
295 # toolkit through it) is loaded on demand so that this module stays loadable --
296 # and banner-free -- without pulling the whole toolkit in.
297 0 ▶sub track_begin ( $trackingJob, $user, $tracking_fields, $mode = undef ) {
Subroutine track_begin: not called CC=3 SCAR=24.8
Pod documented
298 0 ▶ $mode = TRACK_MODE_BATCH() unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 0 0
299 0 require oEdtk::Main;
300 0 require oEdtk::Tracking;
301 0 return oEdtk::Tracking->new(
302 $trackingJob,
303 user => $user,
304 entity => oEdtk::Main::oe_corporation_set(),
305 keys => $tracking_fields,
306 edmode => $mode,
307 );
308 }
309  
310 # Track one document.
311 0 ▶sub track ( $trk, $l, $type = undef ) {
Subroutine track: not called CC=3 SCAR=24.8
Pod documented
312 0 ▶ $type = $TRACK_DOCUMENT unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
313 0 return $trk->track( $type, 1, @{$l} );
314 }
315  
316 # End of tracking.
317 0 ▶sub track_end ($trk) {
Subroutine track_end: not called CC=1 SCAR=6.9
Pod documented
318 0 return $trk->track( $TRACK_WARNING, 1, '', '', '', '', $TRACK_END_MSG );
319 }
320  
321 # --- corporate delegates ---------------------------------------------------
322 # The fork's init() and its INDEX_* accessors call oEUser::Lib or name
323 # corporate schema identifiers, so they live in oEUser::Utils. The old names
324 # are kept here and forwarded on demand; a missing oEUser fails with a clear
325 # message rather than breaking the oEdtk load.
326 0 ▶sub _delegate ( $sub, @args ) {
Subroutine _delegate: not called CC=2 SCAR=17.9
327 0 my $loaded;
328 {
329 0 local $SIG{__DIE__}; # a caught die must not reach oEdtk::Tracking's handler
330 0 $loaded = eval { require oEUser::Utils; 1 };
331 }
332 0 ▶ die "oEdtk::Utils requires the companion distribution oEUser "
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 0 0 0
333 . "(oEUser::Utils is not installed): $@"
334 unless $loaded;
335 0 return oEUser::Utils->can($sub)->(@args);
336 }
337  
338 0 ▶sub init { return _delegate( 'init', @_ ) }
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
339 0 ▶sub INDEX_CLEF_GED { return _delegate( 'INDEX_CLEF_GED', @_ ) }
Subroutine INDEX_CLEF_GED: not called CC=1 SCAR=6.9
Pod undocumented
340 0 ▶sub INDEX_ADRESSE_LISTE { return _delegate( 'INDEX_ADRESSE_LISTE', @_ ) }
Subroutine INDEX_ADRESSE_LISTE: not called CC=1 SCAR=6.9
Pod undocumented
341 0 ▶sub INDEX_ID_MNT_NUMABA { return _delegate( 'INDEX_ID_MNT_NUMABA', @_ ) }
Subroutine INDEX_ID_MNT_NUMABA: not called CC=1 SCAR=6.9
Pod undocumented
342 0 ▶sub INDEX_ID_EMETTEUR { return _delegate( 'INDEX_ID_EMETTEUR', @_ ) }
Subroutine INDEX_ID_EMETTEUR: not called CC=1 SCAR=6.9
Pod undocumented
343 0 ▶sub INDEX_ID_PM_SIRET { return _delegate( 'INDEX_ID_PM_SIRET', @_ ) }
Subroutine INDEX_ID_PM_SIRET: not called CC=1 SCAR=6.9
Pod undocumented
344  
345 2 1;
346  
347 =head1 NAME
348  
349 oEdtk::Utils - generic text, index, date and tracking helpers
350  
351 =head1 SYNOPSIS
352  
353 use oEdtk::Utils qw(delete_useless_whitespaces IDX_FORMAT);
354  
355 my $clean = delete_useless_whitespaces(" a b "); # "a b"
356 my $fmt = IDX_FORMAT();
357  
358 =head1 DESCRIPTION
359  
360 Generic helpers ported from the fork's C<oEdtk::Utils> at S23: text cleanup
361 (C<delete_useless_whitespaces>, C<kill_non_latin_1_9_chars_in_place>,
362 C<trim_list>), the index format (C<IDX_FORMAT>), date and price parsing
363 (C<parse_jjmmaaaa>, C<parse_yyyymmdd>, C<parse_price>, C<convert_date>,
364 C<month_to_name>), tracking (C<track_begin>, C<track>, C<track_end>,
365 C<TRACK_MODE_BATCH>) and small value helpers (C<flatten_index_variables>,
366 C<max_value>, C<scalar_dump>, C<alert>).
367  
368 The corporate part of the fork's module -- C<init> and the C<INDEX_*> accessors,
369 which call L<oEUser::Lib> or name corporate schema identifiers -- lives in
370 L<oEUser::Utils>. Their old names are kept here as delegates: they forward to
371 the companion distribution, which is loaded on demand, and a missing oEUser
372 fails with a clear message. This module itself never depends on oEUser.
373  
374 =head1 FUNCTIONS
375  
376 =head2 delete_useless_whitespaces
377  
378 my $clean = delete_useless_whitespaces($string);
379  
380 Remove the surrounding whitespace and collapse internal runs to a single space.
381 Croaks on an undef argument.
382  
383 =head2 IDX_FORMAT
384  
385 my $format = IDX_FORMAT();
386  
387 Return the current index format, an array reference of C<[ old_tag, new_field,
388 offset ]> entries.
389  
390 =head2 kill_non_latin_1_9_chars_in_place
391  
392 kill_non_latin_1_9_chars_in_place(\$string);
393  
394 Replace, in place, the DEL and C1 control bytes of C<$string> with spaces.
395  
396 =head2 alert
397  
398 alert($flow_file, $line_number, $message, @objects);
399  
400 Carp an alert carrying the flow file, the line number and the objects.
401  
402 =head2 flatten_index_variables
403  
404 my $index = flatten_index_variables($record);
405  
406 Return a hash reference of the C<index_variables> sub-hash, each key prefixed
407 with C<index>.
408  
409 =head2 max_value
410  
411 my $max = max_value(\@values);
412  
413 Return the greatest value of the list reference, compared as strings.
414  
415 =head2 parse_jjmmaaaa
416  
417 my $parts = parse_jjmmaaaa($string, $flow_file, $line_number);
418  
419 Parse a dd/mm/yyyy string into C<[ day, "month_name year" ]>, or raise an alert
420 and return.
421  
422 =head2 parse_price
423  
424 my $price = parse_price($number, $flow_file, $line_number);
425  
426 Return the price unchanged when it is valid, otherwise raise an alert.
427  
428 =head2 parse_yyyymmdd
429  
430 my $parts = parse_yyyymmdd($string, $flow_file, $line_number);
431  
432 Parse a yyyymmdd string into C<[ day, "month_name year" ]>, or raise an alert
433 and return.
434  
435 =head2 scalar_dump
436  
437 my $readable = scalar_dump($string);
438  
439 Render the non-printable bytes of C<$string> as hexadecimal escapes, for display.
440  
441 =head2 track
442  
443 track($tracking, \@fields, $type);
444  
445 Track one document on the given tracking object, with an optional event type.
446  
447 =head2 track_begin
448  
449 my $tracking = track_begin($job, $user, \@fields, $mode);
450  
451 Start tracking and return the tracking object. The tracking class and the
452 toolkit are loaded on demand.
453  
454 =head2 track_end
455  
456 track_end($tracking);
457  
458 Record the end-of-run tracking event on the given object.
459  
460 =head2 trim_list
461  
462 my $string = trim_list(@parts);
463  
464 Join the list with single spaces, collapsing runs of whitespace.
465  
466 The unexported helpers C<check_date>, C<convert_date>, C<month_to_name>,
467 C<my_dumper>, C<latest_idx1_in_directory>, C<comment_index_file>,
468 C<TRACK_MODE_BATCH> and C<_delegate>, and the corporate accessors C<init> and the
469 C<INDEX_*> names, are not part of the public API; the accessors delegate on
470 demand to the companion C<oEUser::Utils>.
471  
472 =head1 AUTHOR
473  
474 The oEdtk team.
475  
476 =cut
« blib/lib/oEdtk/TexTag.pm ↑ Summary blib/lib/oEdtk/Messenger.pm »