Quiq/KositValidator.pm

filter: Statementstmt 38.7% 19 / 49 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 38.0% 27 / 71 CC 7 SCAR 26.2
CC
7
Cov
31%
validate
30.0
new
12.0
BEGIN
1.0
CRAP 13.7
« Quiq/Properties.pm ↑ Summary Quiq/Debug.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::KositValidator - Validator für XRechnungen
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Der Validator ist eine Zusammenstellung aus Java-Code und
16 Schematron-Dateien zur Validierung von XRechnungs-XML.
17  
18 Der Validator ist im jeweils aktuellen "XRechnung Bundle" enhalten,
19 welcher von L<XRechnung Versionen und Bundles|https://xeinkauf.de/xrechnung/versionen-und-bundles/>
20 heruntergeladen werden kann.
21  
22 =over 4
23  
24 =item 1.
25  
26 Bundle herunterladen und entpacken
27  
28 $ mkdir xrechnung-3.0.2-bundle-2025-07-10
29 $ cd xrechnung-3.0.2-bundle-2025-07-10
30 $ unzip ../xrechnung-3.0.2-bundle-2025-07-10.zip
31  
32 =item 2.
33  
34 KoSIT-Validator aus dem Bundle heraus entpacken und installieren
35  
36 Beispiel-Verzeichnis ist C<~/sys/opt/kosit-validator>, dieses kann
37 aber frei gewählt werden.
38  
39 $ mkdir ~/sys/opt/kosit-validator
40 $ cd ~/sys/opt/kosit-validator
41 $ unzip .../validator-1.5.0-distribution.zip
42 $ unzip .../validator-configuration-xrechnung_3.0.2_2025-07-10.zip
43  
44 =item 3.
45  
46 KoSIT-Validator testen
47  
48 Eine Beispiel-Datei C<ubl.xml> wird zum Herunterladen in
49 C<kosit-validator/docs/usage.md> erwähnt.
50  
51 $ perl -MQuiq::KositValidator -E '$kvl = Quiq::KositValidator->new("~/sys/opt/kosit-validator");say $kvl->validate("ubl.xml")'
52  
53 Es kann z.B. auch eine EN16931 ZUGFeRD XML-Datei validiert werden.
54  
55 =back
56  
57 =cut
58  
59 # -----------------------------------------------------------------------------
60  
61 package Quiq::KositValidator;
62 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 1 our $VERSION = '1.240';
69  
70 1 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 ▶use Quiq::Shell;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 # -----------------------------------------------------------------------------
74  
75 =head1 METHODS
76  
77 =head2 Klassenmethoden
78  
79 =head3 new() - Konstruktor
80  
81 =head4 Synopsis
82  
83 $kvl = $class->new($validatorDir,%options);
84  
85 =head4 Arguments
86  
87 =over 4
88  
89 =item $validatorDir
90  
91 Verzeichnis mit den zum Validator gehörenden Dateien
92  
93 =back
94  
95 =head4 Options
96  
97 =over 4
98  
99 =item -javaDir => $javaDir (Default: undef)
100  
101 Verzeichns mit dem Programm C<java>. Beispiel: C</opt/jdk/bin>
102  
103 =back
104  
105 =head4 Returns
106  
107 Validator-Objekt
108  
109 =head4 Description
110  
111 Instantiiere ein Objekt der Klasse und liefere eine Referenz auf
112 dieses Objekt zurück.
113  
114 =cut
115  
116 # -----------------------------------------------------------------------------
117  
118 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
119 0 my $class = shift;
120  
121 # Optionen und Argumente
122  
123 0 my $javaDir = undef;
124  
125 0 my $argA = $class->parameters(1,1,\@_,
126 -javaDir => \$javaDir,
127 );
128 0 my $validatorDir = shift @$argA;
129  
130 # Führe Operation aus
131  
132 0 ▶ if (!Quiq::Path->exists($validatorDir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Quiq::Path"->exists($validatorDir)) 0 0 0
133 0 $class->throw(
134 'MUSTANG-00099: Directory does not exists',
135 ValidatorDir => $validatorDir,
136 );
137 }
138  
139 0 my $javaExe = 'java';
140 0 ▶ if ($javaDir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($javaDir) 0 0 0
141 0 $javaExe = "$javaDir/$javaExe";
142 }
143  
144 0 return $class->SUPER::new(
145 validatorDir => $validatorDir,
146 javaExe => $javaExe,
147 );
148 }
149  
150 # -----------------------------------------------------------------------------
151  
152 =head2 Objektmethoden
153  
154 =head3 validate() - Validiere XRechnungs-XML
155  
156 =head4 Synopsis
157  
158 $status = $kvl->validate($xmlFile,%options);
159  
160 =head4 Arguments
161  
162 =over 4
163  
164 =item $xmlFile
165  
166 Datei mit XRechnungs-XML
167  
168 =back
169  
170 =head4 Options
171  
172 =over 4
173  
174 =item -verbose => $bool (Default: 0)
175  
176 Gib Laufzeitinformation über die Verarbeitung auf STDOUT aus.
177  
178 =back
179  
180 =head4 Returns
181  
182 (Integer) Status der Validierung: 0 = ok, 1 = fehlgeschlagen.
183  
184 =head4 Description
185  
186 Validiere XRechnungs-XML-Datei $xmlFile und liefere den Status der
187 Validierung zurück.
188  
189 =cut
190  
191 # -----------------------------------------------------------------------------
192  
193 0 ▶sub validate {
Subroutine validate: not called CC=5 SCAR=34.0
Pod documented
194 0 my $self = shift;
195  
196 0 my $p = Quiq::Path->new;
197  
198 # Optionen und Argumente
199  
200 0 my $log = undef;
201 0 my $verbose = 0;
202  
203 0 my $argA = $self->parameters(1,1,\@_,
204 -logger => \$log,
205 -verbose => \$verbose,
206 );
207 0 my $xmlFile = $p->expandTilde(shift @$argA);
208  
209 # Führe Operation aus
210  
211 0 my $sh = Quiq::Shell->new(log=>0);
212  
213 0 ▶ if (!Quiq::Path->exists($xmlFile)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Quiq::Path"->exists($xmlFile)) 0 0 0
214 0 $self->throw(
215 'MUSTANG-00099: File does not exists',
216 XmlFile => $xmlFile,
217 );
218 }
219  
220 0 my ($javaExe,$validatorDir) = $self->get(qw/javaExe validatorDir/);
221 0 my $jar = "$validatorDir/validationtool-1.5.0-standalone.jar";
222 0 my $scenariosFile = "$validatorDir/scenarios.xml";
223 0 my $xmlFileDir = $p->dir($xmlFile);
224  
225 0 my $cmd = "$javaExe -jar $jar -r $validatorDir -s $scenariosFile".
226 qq| -o "$xmlFileDir" "$xmlFile"|;
227 0 ▶ if ($verbose) {
Branch: 2 branches
BranchTrueFalseTotal
if ($verbose) { } 0 0 0
elsif ($log) { } 0 0 0
228 0 say $cmd;
229 }
230 elsif ($log) {
231 0 $log->info("Validiere XRechnungs-XML: $cmd");
232 }
233 0 my $stdout = $sh->exec($cmd,-sloppy=>1,-capture=>'stdout');
234 0 ▶ my $status = $stdout =~ /Validation successful/i? 0: 1;
Branch: 1 branch
BranchTrueFalseTotal
$stdout =~ /Validation successful/i ? : 0 0 0
235  
236 0 return $status;
237 }
238  
239 # -----------------------------------------------------------------------------
240  
241 =head1 VERSION
242  
243 1.240
244  
245 =head1 AUTHOR
246  
247 Frank Seitz, L<http://fseitz.de/>
248  
249 =head1 COPYRIGHT
250  
251 Copyright (C) 2026 Frank Seitz
252  
253 =head1 LICENSE
254  
255 This code is free software; you can redistribute it and/or modify
256 it under the same terms as Perl itself.
257  
258 =cut
259  
260 # -----------------------------------------------------------------------------
261  
262 1 1;
263  
264 # eof
« Quiq/Properties.pm ↑ Summary Quiq/Debug.pm »