| 1 | package OPM::Validate; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Validate .opm files | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use v5.20; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '1.13'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my %boundaries = ( | |||||||||||||||||||||||||||
| 13 | # tag min max | ||||||||||||||||||||||||||||
| 14 | CVS => [ 0, 1], | ||||||||||||||||||||||||||||
| 15 | Name => [ 1, 1], | ||||||||||||||||||||||||||||
| 16 | URL => [ 1, 1], | ||||||||||||||||||||||||||||
| 17 | Vendor => [ 1, 1], | ||||||||||||||||||||||||||||
| 18 | Version => [ 1, 1], | ||||||||||||||||||||||||||||
| 19 | BuildDate => [ 0, 1], | ||||||||||||||||||||||||||||
| 20 | BuildHost => [ 0, 1], | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 21 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 21 | my ($class, $content, $is_sopm) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 21 | $content =~ s{ | |||||||||||||||||||||||||||
| 27 | <!-- .*? --> | ||||||||||||||||||||||||||||
| 28 | }{}xmsg; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 21 | my ($check,$grammar) = _grammar( $content, $is_sopm ); | |||||||||||||||||||||||||||
| 31 | 21 | my $match = $content =~ $grammar; | |||||||||||||||||||||||||||
| 32 | 21 | ▶ | die 'Invalid .opm file' if !$match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 17 | for my $key ( keys %boundaries ) { | |||||||||||||||||||||||||||
| 35 | 119 | $check->( $key ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 21 | ▶ | sub _grammar { | ||||||||||||||||||||||||||
|
Subroutine
_grammar: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 40 | 21 | my ($content, $is_sopm) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 21 | ▶ | $is_sopm //= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$is_sopm //= 0
MC/DC100%1/1
$is_sopm //= 0
$is_sopm
Truth table100%2/2
A
A= $is_sopm
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 21 | my %s; | |||||||||||||||||||||||||||
| 45 | my %pos; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1104 | ▶ | my $check = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=28.1
| |||||||||||||||||||||||||||||
| 48 | 1104 | my ($name, $max, $min) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1104 | ▶ | $max //= (exists $boundaries{$name} ? $boundaries{$name}->[-1] : 100_000); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$max //= exists $boundaries{$name} ? $boundaries{$name}[-1] : 100000
MC/DC0%0/2
$max //= exists $boundaries{$name} ? $boundaries{$name}[-1] : 100000
$max
exists $boundaries{$name} ? $boundaries{$name}[-1] : 100000
Truth table66%2/3
A //= B
A= $maxB= exists $boundaries{$name} ? $boundaries{$name}[-1] : 100000
| |||||||||||||||||||||||||||||
| 51 | 1104 | ▶ | $min //= (exists $boundaries{$name} ? $boundaries{$name}->[0] : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$min //= exists $boundaries{$name} ? $boundaries{$name}[0] : 0
MC/DC0%0/2
$min //= exists $boundaries{$name} ? $boundaries{$name}[0] : 0
$min
exists $boundaries{$name} ? $boundaries{$name}[0] : 0
Truth table66%2/3
A //= B
A= $minB= exists $boundaries{$name} ? $boundaries{$name}[0] : 0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1104 | my ($first,$second) = split /\./, $name; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1104 | ▶ | my $check = $s{$name} // 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$s{$name} // 0
MC/DC100%1/1
$s{$name} // 0
$s{$name}
Truth table100%2/2
A
A= $s{$name}
| |||||||||||||||||||||||||||||
| 56 | 1104 | ▶ | if ( $second && ref $s{$first} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$second and ref $s{$first}
MC/DC100%2/2
$second and ref $s{$first}
$second
ref $s{$first}
Truth table100%3/3
A and B
A= $secondB= ref $s{$first}
| |||||||||||||||||||||||||||||
| 57 | 692 | ▶ | $check = $s{$first}->{$second} // 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$s{$first}{$second} // 0
MC/DC0%0/1
$s{$first}{$second} // 0
$s{$first}{$second}
Truth table50%1/2
A
A= $s{$first}{$second}
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1104 | my $context = ''; | |||||||||||||||||||||||||||
| 61 | 1104 | my $pos = $pos{$name}; | |||||||||||||||||||||||||||
| 62 | 1104 | ▶ | if ( $pos ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 88 | my $start_length = 30; | |||||||||||||||||||||||||||
| 64 | 88 | my $start = $pos - $start_length; | |||||||||||||||||||||||||||
| 65 | 88 | ▶ | if ( $start < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $start_length = $pos; | |||||||||||||||||||||||||||
| 67 | 0 | $start = 0; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 88 | my $end_length = 30; | |||||||||||||||||||||||||||
| 71 | 88 | ▶ | if ( $pos + $end_length > length $content ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | $end_length = ( length $content ) - $pos; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 88 | $context = sprintf "\n%s <-- --> %s", | |||||||||||||||||||||||||||
| 76 | ( substr $content, $start, $start_length ), | ||||||||||||||||||||||||||||
| 77 | ( substr $content, $pos, $end_length ); | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1104 | ▶ | if ( $check > $max ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 81 | 0 | die sprintf 'Too many "%s" elements. Max %s element(s) allowed.%s', $name, $max, $context; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | elsif ( $check < $min ) { | ||||||||||||||||||||||||||||
| 84 | 0 | die sprintf 'Too few "%s" elements. Min %s element(s) required.%s', $name, $min, $context; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 21 | }; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | my $grammar = qr{ | ||||||||||||||||||||||||||||
| 89 | \A(?&PACKAGE)\z | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | (?(DEFINE) | ||||||||||||||||||||||||||||
| 92 | (?<PACKAGE> | ||||||||||||||||||||||||||||
| 93 | \s* <\?xml \s* version="1.0" \s* encoding="[^"]+?" \s* \?> \s+ | ||||||||||||||||||||||||||||
| 94 | \s* <(?<product>otrs|otobo)_package \s+ version="[12].[0-9]+"> | ||||||||||||||||||||||||||||
| 95 | (?:\s*(?&PACKAGE_TAGS))+ | ||||||||||||||||||||||||||||
| 96 | \s* </\g{product}_package> \s* | ||||||||||||||||||||||||||||
| 97 | ) | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | (?<PACKAGE_TAGS> | ||||||||||||||||||||||||||||
| 100 | (?:<CVS>.*?</CVS>(?{$pos{CVS} = pos(); $s{CVS}++; $check->('CVS')})) | | ||||||||||||||||||||||||||||
| 101 | (?:<Name>.*?</Name>(?{$pos{Name} = pos(); ++$s{Name}; $check->('Name')})) | | ||||||||||||||||||||||||||||
| 102 | (?:<Version>.*?</Version>(?{++$s{Version}; $check->('Version')})) | | ||||||||||||||||||||||||||||
| 103 | (?:<Vendor>.*?</Vendor>(?{++$s{Vendor}; $check->('Vendor')})) | | ||||||||||||||||||||||||||||
| 104 | (?:<URL>.*?</URL>(?{++$s{URL}; $check->('URL')})) | | ||||||||||||||||||||||||||||
| 105 | (?:<License>.*?</License>(?{++$s{License}; $check->('License')})) | | ||||||||||||||||||||||||||||
| 106 | (?:<BuildDate>.*?</BuildDate>(?{$s{BuildDate}++; $check->('BuildDate')})) | | ||||||||||||||||||||||||||||
| 107 | (?:<BuildHost>.*?</BuildHost>(?{$s{BuildHost}++; $check->('BuildHost')})) | | ||||||||||||||||||||||||||||
| 108 | (?:<BuildCommitID>.*?</BuildCommitID>) | | ||||||||||||||||||||||||||||
| 109 | (?:<PackageIsDownloadable>.*?</PackageIsDownloadable>) | | ||||||||||||||||||||||||||||
| 110 | (?:<OS>.*?</OS>) | | ||||||||||||||||||||||||||||
| 111 | (?&FRAMEWORK) | | ||||||||||||||||||||||||||||
| 112 | (?&DESCRIPTION) | | ||||||||||||||||||||||||||||
| 113 | (?&INTRO) | | ||||||||||||||||||||||||||||
| 114 | (?&CODE) | | ||||||||||||||||||||||||||||
| 115 | (?&PACKAGEMERGE) | | ||||||||||||||||||||||||||||
| 116 | (?&FILELIST) | | ||||||||||||||||||||||||||||
| 117 | (?&PREREQ) | | ||||||||||||||||||||||||||||
| 118 | (?&DATABASE) | | ||||||||||||||||||||||||||||
| 119 | (?&CHANGELOG) | ||||||||||||||||||||||||||||
| 120 | ) | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | (?<CUSTOM> | ||||||||||||||||||||||||||||
| 123 | <(?<custom>[A-Za-z0-9]+)[^>]*>.*?</\g{custom}>(?{ print $+{custom},"\n" }) | ||||||||||||||||||||||||||||
| 124 | ) | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | (?<FRAMEWORK> | ||||||||||||||||||||||||||||
| 127 | <Framework (?{delete @s{'Framework.Min','Framework.Max'}}) ( \s+ (?&FRAMEWORK_ATTR))*>.*?</Framework> | ||||||||||||||||||||||||||||
| 128 | (*COMMIT) | ||||||||||||||||||||||||||||
| 129 | ) | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | (?<FRAMEWORK_ATTR> | ||||||||||||||||||||||||||||
| 132 | (?:Maximum="[0-9\.]+"(?{++$s{'Framework.Max'}; $check->('Framework.Max',1)})) | | ||||||||||||||||||||||||||||
| 133 | (?:Minimum="[0-9\.]+"(?{++$s{'Framework.Min'}; $check->('Framework.Min',1)})) | ||||||||||||||||||||||||||||
| 134 | ) | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | (?<DESCRIPTION> | ||||||||||||||||||||||||||||
| 137 | <Description (?{delete $s{'Description.Lang'}}) ( \s+ (?&DESCRIPTION_ATTR))*>.*?</Description> | ||||||||||||||||||||||||||||
| 138 | (*COMMIT) | ||||||||||||||||||||||||||||
| 139 | ) | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | (?<DESCRIPTION_ATTR> | ||||||||||||||||||||||||||||
| 142 | (?:Lang="(?<lang>[a-zA-Z]+)"(?{++$s{'Description.Lang'}; $check->('Description.Lang',1)})) | | ||||||||||||||||||||||||||||
| 143 | (?:Format="[a-zA-Z]+"(?{++$s{'Description.Format'}; $check->('Description.Format',1)})) | | ||||||||||||||||||||||||||||
| 144 | (?:Translatable="[01]"(?{++$s{'Description.Translatable'}; $check->('Description.Translatable',1)})) | ||||||||||||||||||||||||||||
| 145 | ) | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | (?<CHANGELOG> | ||||||||||||||||||||||||||||
| 148 | <ChangeLog (?{delete $s{'ChangeLog.Date'}; delete $s{'ChangeLog.Version'}; }) | ||||||||||||||||||||||||||||
| 149 | ( \s+ (?&CHANGELOG_ATTR))*>.*? | ||||||||||||||||||||||||||||
| 150 | </ChangeLog> (?{$check->('ChangeLog.Date', 1, 0); $check->('ChangeLog.Version', 1, 0); }) | ||||||||||||||||||||||||||||
| 151 | (*COMMIT) | ||||||||||||||||||||||||||||
| 152 | ) | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | (?<CHANGELOG_ATTR> | ||||||||||||||||||||||||||||
| 155 | (?:Date="[^"]+"(?{++$s{'ChangeLog.Date'}; $check->('ChangeLog.Date',1,1)})) | | ||||||||||||||||||||||||||||
| 156 | (?:Version="[0-9\.]+"(?{++$s{'ChangeLog.Version'}; $check->('ChangeLog.Version',1,1)})) | ||||||||||||||||||||||||||||
| 157 | ) | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | (?<INTRO> | ||||||||||||||||||||||||||||
| 160 | <Intro(?<intro_type>Install|Upgrade|Reinstall|Uninstall)(?{delete $s{Intro};}) | ||||||||||||||||||||||||||||
| 161 | (?:(?<intro_pre_post>Pre|Post|)(?{++$s{Intro}->{Type} if $+{intro_pre_post}}))? | ||||||||||||||||||||||||||||
| 162 | ( \s+ (?&INTRO_ATTR))+>.*? | ||||||||||||||||||||||||||||
| 163 | </Intro\g{intro_type}\g{intro_pre_post}> (?{$check->('Intro.Type', 1, 1);}) | ||||||||||||||||||||||||||||
| 164 | (*COMMIT) | ||||||||||||||||||||||||||||
| 165 | ) | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | (?<INTRO_ATTR> | ||||||||||||||||||||||||||||
| 168 | (?:Type="(?i:Post|Pre)"(?{++$s{Intro}->{Type}; $check->('Intro.Type',1,1)})) | | ||||||||||||||||||||||||||||
| 169 | (?:Title="[^"]*"(?{++$s{Intro}->{Title}; $check->('Intro.Title',1)})) | | ||||||||||||||||||||||||||||
| 170 | (?:Format="[^"]*"(?{++$s{Intro}->{Format}; $check->('Intro.Format',1)})) | | ||||||||||||||||||||||||||||
| 171 | (?:Lang="[A-Za-z]+"(?{++$s{Intro}->{Lang}; $check->('Intro.Lang',1)})) | | ||||||||||||||||||||||||||||
| 172 | (?:Translatable="[01]"(?{++$s{Intro}->{Translatable}; $check->('Intro.Translatable',1)})) | | ||||||||||||||||||||||||||||
| 173 | (?:Version="[0-9\.]+"(?{++$s{Intro}->{Version}; $check->('Intro.Version',$+{intro_type} eq 'Upgrade' ? 1 : 0)})) | ||||||||||||||||||||||||||||
| 174 | ) | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | (?<CODE> | ||||||||||||||||||||||||||||
| 177 | <Code(?<code_type>Install|Upgrade|Reinstall|Uninstall) (?{delete $s{Code};}) | ||||||||||||||||||||||||||||
| 178 | ( \s+ (?&CODE_ATTR))*>.*? | ||||||||||||||||||||||||||||
| 179 | </Code\g{code_type}> (?{$check->('Code.Type', 1);}) | ||||||||||||||||||||||||||||
| 180 | (*COMMIT) | ||||||||||||||||||||||||||||
| 181 | ) | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | (?<CODE_ATTR> | ||||||||||||||||||||||||||||
| 184 | (?:Type="(?i:Post|Pre)"(?{++$s{Code}->{Type}; $check->('Code.Type',1,1)})) | | ||||||||||||||||||||||||||||
| 185 | (?:Version="[^"]+"(?{++$s{Code}->{Version}; $check->('Code.Version',$+{code_type} eq 'Upgrade' ? 1 : 0)})) | ||||||||||||||||||||||||||||
| 186 | ) | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | (?<PREREQ> | ||||||||||||||||||||||||||||
| 189 | <(?<prereq_type>Module|Package)Required (?{delete $s{Prereq};}) | ||||||||||||||||||||||||||||
| 190 | (\s+ (?&VERSION))?>.+? | ||||||||||||||||||||||||||||
| 191 | </\g{prereq_type}Required> (?{$check->('Prereq.Version', 1); delete $s{Prereq}}) | ||||||||||||||||||||||||||||
| 192 | (*COMMIT) | ||||||||||||||||||||||||||||
| 193 | ) | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | (?<VERSION> | ||||||||||||||||||||||||||||
| 196 | (?:Version="[^"]+"(?{++$s{Prereq}->{Version}; $check->('Prereq.Version', 1)})) | ||||||||||||||||||||||||||||
| 197 | ) | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | (?<PACKAGEMERGE> | ||||||||||||||||||||||||||||
| 200 | <PackageMerge (?{delete $s{'Merge.Name'};}) | ||||||||||||||||||||||||||||
| 201 | (\s+ (?&PACKAGEMERGEATTR))+>.*? | ||||||||||||||||||||||||||||
| 202 | </PackageMerge> (?{$check->('Merge.Name', 1, 1);}) | ||||||||||||||||||||||||||||
| 203 | (*COMMIT) | ||||||||||||||||||||||||||||
| 204 | ) | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | (?<PACKAGEMERGEATTR> | ||||||||||||||||||||||||||||
| 207 | (?:TargetVersion="[0-9\.]+"(?{++$s{'Merge.Version'}; $check->('Merge.Version', 1)})) | | ||||||||||||||||||||||||||||
| 208 | (?:Name="[^"]+"(?{++$s{'Merge.Name'};})) | ||||||||||||||||||||||||||||
| 209 | ) | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | (?<FILELIST> | ||||||||||||||||||||||||||||
| 213 | <Filelist>(\s*(?(?{$is_sopm})(?&FILESOPM)|(?&FILEOPM)))+\s*</Filelist> | ||||||||||||||||||||||||||||
| 214 | (*COMMIT) | ||||||||||||||||||||||||||||
| 215 | ) | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | (?<FILESOPM> | ||||||||||||||||||||||||||||
| 218 | <File (?{delete $s{File};}) | ||||||||||||||||||||||||||||
| 219 | ( \s+ (?&FILE_ATTR))+ \s* />(?{$check->('File.' . $_ , 1, 1) for qw/Location Permission/;}) | ||||||||||||||||||||||||||||
| 220 | (*COMMIT) | ||||||||||||||||||||||||||||
| 221 | ) | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | (?<FILEOPM> | ||||||||||||||||||||||||||||
| 224 | <File (?{delete $s{File};}) | ||||||||||||||||||||||||||||
| 225 | ( \s+ (?&FILE_ATTR))+ \s* > \s* [A-Za-z0-9\+/\s]+ (*COMMIT) ={0,3} \s*? | ||||||||||||||||||||||||||||
| 226 | </File> (?{$check->('File.' . $_ , 1, 1) for qw/Location Permission Encode/;}) | ||||||||||||||||||||||||||||
| 227 | (*COMMIT) | ||||||||||||||||||||||||||||
| 228 | ) | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | (?<FILE_ATTR> | ||||||||||||||||||||||||||||
| 231 | (?:Location="[^"]+"(?{++$s{File}->{Location};})) | | ||||||||||||||||||||||||||||
| 232 | (?:Encode="[^"]+"(?{++$s{File}->{Encode};})) | | ||||||||||||||||||||||||||||
| 233 | (?:Permission="[0-7]+"(?{++$s{File}->{Permission};})) | ||||||||||||||||||||||||||||
| 234 | ) | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | (?<DATABASE> | ||||||||||||||||||||||||||||
| 237 | <Database(?<database_type>Install|Upgrade|Reinstall|Uninstall) (?{delete $s{Database}}) | ||||||||||||||||||||||||||||
| 238 | ( \s+ (?&DATABASE_ATTR)){0,3}> | ||||||||||||||||||||||||||||
| 239 | (\s* (?&DATABASE_TAGS) )* \s* | ||||||||||||||||||||||||||||
| 240 | </Database\g{database_type}> | ||||||||||||||||||||||||||||
| 241 | (*COMMIT) | ||||||||||||||||||||||||||||
| 242 | ) | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | (?<DATABASE_ATTR> | ||||||||||||||||||||||||||||
| 245 | (?:Type="(?i:Post|Pre)"(?{++$s{Database}->{Type}; $check->('Database.Type',1)})) | | ||||||||||||||||||||||||||||
| 246 | (?:Version="[^"]+"(?{++$s{Database}->{Version}; $check->('Database.Version',1)})) | ||||||||||||||||||||||||||||
| 247 | ) | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | (?<DATABASE_TAGS> | ||||||||||||||||||||||||||||
| 250 | (?&TABLE_CREATE) | | ||||||||||||||||||||||||||||
| 251 | (?&TABLE_DROP) | | ||||||||||||||||||||||||||||
| 252 | (?&TABLE_ALTER) | | ||||||||||||||||||||||||||||
| 253 | (?&INSERT) | ||||||||||||||||||||||||||||
| 254 | ) | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | (?<TABLE_CREATE> | ||||||||||||||||||||||||||||
| 257 | <TableCreate (?{delete $s{Table}}) | ||||||||||||||||||||||||||||
| 258 | (?: \s+ (?&TABLE_ATTR))+ \s*> | ||||||||||||||||||||||||||||
| 259 | (?: \s* (?&TABLE_CREATE_TAGS) )+ \s* | ||||||||||||||||||||||||||||
| 260 | </TableCreate> | ||||||||||||||||||||||||||||
| 261 | (*COMMIT) | ||||||||||||||||||||||||||||
| 262 | ) | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | (?<TABLE_CREATE_TAGS> | ||||||||||||||||||||||||||||
| 265 | (?&COLUMN) | | ||||||||||||||||||||||||||||
| 266 | (?&FOREIGN_KEY) | | ||||||||||||||||||||||||||||
| 267 | (?&INDEX) | | ||||||||||||||||||||||||||||
| 268 | (?&UNIQUE) | ||||||||||||||||||||||||||||
| 269 | ) | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | (?<TABLE_ALTER> | ||||||||||||||||||||||||||||
| 272 | <TableAlter (?{delete $s{Table};}) | ||||||||||||||||||||||||||||
| 273 | ( \s+ (?&TABLE_ALTER_ATTR))+> | ||||||||||||||||||||||||||||
| 274 | (\s* (?&TABLE_ALTER_TAGS) )*? \s* | ||||||||||||||||||||||||||||
| 275 | </TableAlter> | ||||||||||||||||||||||||||||
| 276 | (*COMMIT) | ||||||||||||||||||||||||||||
| 277 | ) | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | (?<TABLE_ALTER_ATTR> | ||||||||||||||||||||||||||||
| 280 | (?&TABLE_ATTR) | | ||||||||||||||||||||||||||||
| 281 | (?: \s* NameNew="[^"]*?") | | ||||||||||||||||||||||||||||
| 282 | (?: \s* NameOld="[^"]*?") | ||||||||||||||||||||||||||||
| 283 | ) | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | (?<TABLE_ALTER_TAGS> | ||||||||||||||||||||||||||||
| 286 | (?&COLUMN_ADD) | | ||||||||||||||||||||||||||||
| 287 | (?&COLUMN_DROP) | | ||||||||||||||||||||||||||||
| 288 | (?&COLUMN_CHANGE) | | ||||||||||||||||||||||||||||
| 289 | (?&FOREIGN_KEY_CREATE) | | ||||||||||||||||||||||||||||
| 290 | (?&FOREIGN_KEY_DROP) | | ||||||||||||||||||||||||||||
| 291 | (?&INDEX_CREATE) | | ||||||||||||||||||||||||||||
| 292 | (?&INDEX_DROP) | | ||||||||||||||||||||||||||||
| 293 | (?&UNIQUE_CREATE) | | ||||||||||||||||||||||||||||
| 294 | (?&UNIQUE_DROP) | ||||||||||||||||||||||||||||
| 295 | ) | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | (?<TABLE_DROP> | ||||||||||||||||||||||||||||
| 298 | <TableDrop (?{delete $s{Table};}) | ||||||||||||||||||||||||||||
| 299 | ( \s+ (?&TABLE_ATTR))+ \s* (?:/>|>\s*</TableDrop>) | ||||||||||||||||||||||||||||
| 300 | (*COMMIT) | ||||||||||||||||||||||||||||
| 301 | ) | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | (?<TABLE_ATTR> | ||||||||||||||||||||||||||||
| 304 | (?:Name="([^"]+)"(?{$pos{'Table.Name'} = pos(); ++$s{Table}->{Name}; $check->('Table.Name',1,1)})) | | ||||||||||||||||||||||||||||
| 305 | (?:Type="(?i:Post|Pre)"(?{++$s{Table}->{Type}; $check->('Table.Type',1)})) | | ||||||||||||||||||||||||||||
| 306 | (?:Version="[^"]+"(?{++$s{Table}->{Version}; $check->('Table.Version', 1)})) | ||||||||||||||||||||||||||||
| 307 | ) | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | (?<COLUMN> | ||||||||||||||||||||||||||||
| 310 | <Column (?{delete $s{Column}}) | ||||||||||||||||||||||||||||
| 311 | ( \s+ (?&COLUMN_ATTR))+ \s* (?:/>|>\s*</Column>) | ||||||||||||||||||||||||||||
| 312 | (*COMMIT) | ||||||||||||||||||||||||||||
| 313 | ) | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | (?<COLUMN_ADD> | ||||||||||||||||||||||||||||
| 316 | <ColumnAdd (?{delete $s{Column}}) | ||||||||||||||||||||||||||||
| 317 | ( \s+ (?&COLUMN_ATTR))+ \s* (?:/>|>\s*</ColumnAdd>) | ||||||||||||||||||||||||||||
| 318 | (*COMMIT) | ||||||||||||||||||||||||||||
| 319 | ) | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | (?<COLUMN_ATTR> | ||||||||||||||||||||||||||||
| 322 | (?:Name="[^"]+"(?{++$s{Column}->{Name}; $check->('Column.Name',1,1);})) | | ||||||||||||||||||||||||||||
| 323 | (?:AutoIncrement="(?i:true|false)"(?{++$s{Column}->{AutoIncrement}; $check->('Column.AutoIncrement',1)})) | | ||||||||||||||||||||||||||||
| 324 | (?:Required="(?i:true|false|0|1)"(?{++$s{Column}->{Required}; $check->('Column.Required',1)})) | | ||||||||||||||||||||||||||||
| 325 | (?:PrimaryKey="(?i:true|false)"(?{++$s{Column}->{PrimaryKey}; $check->('Column.PrimaryKey',1)})) | | ||||||||||||||||||||||||||||
| 326 | (?:\bType="[A-Za-z]+"(?{++$s{Column}->{Type}; $check->('Column.Type',1)})) | | ||||||||||||||||||||||||||||
| 327 | (?:Size="\d+(?:,\d+)?"(?{++$s{Column}->{Size}; $check->('Column.Size',1)})) | | ||||||||||||||||||||||||||||
| 328 | (?:Default="[^"]+"(?{++$s{Column}->{Default}; $check->('Column.Default',1)})) | ||||||||||||||||||||||||||||
| 329 | ) | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | (?<COLUMN_CHANGE> | ||||||||||||||||||||||||||||
| 332 | <ColumnChange (?{delete $s{Column}}) | ||||||||||||||||||||||||||||
| 333 | (?: \s+ (?&COLUMN_CHANGE_ATTR))+ \s* (?:/>|>\s*</ColumnChange>) | ||||||||||||||||||||||||||||
| 334 | (*COMMIT) | ||||||||||||||||||||||||||||
| 335 | ) | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | (?<COLUMN_CHANGE_ATTR> | ||||||||||||||||||||||||||||
| 338 | (?:NameOld="[^"]*?"(?{++$s{Column}->{NameOld}; $check->('Column.NameOld',1)})) | | ||||||||||||||||||||||||||||
| 339 | (?:NameNew="[^"]*?"(?{++$s{Column}->{NameNew}; $check->('Column.NameNew',1)})) | | ||||||||||||||||||||||||||||
| 340 | (?:AutoIncrement="(?:true|false)"(?{++$s{Column}->{AutoIncrement}; $check->('Column.AutoIncrement',1)})) | | ||||||||||||||||||||||||||||
| 341 | (?:Required="(?:true|false|0|1)"(?{++$s{Column}->{Required}; $check->('Column.Required',1)})) | | ||||||||||||||||||||||||||||
| 342 | (?:PrimaryKey="(?:true|false)"(?{++$s{Column}->{PrimaryKey}; $check->('Column.PrimaryKey',1)})) | | ||||||||||||||||||||||||||||
| 343 | (?:Type=".*?"(?{++$s{Column}->{Type}; $check->('Column.Type',1)})) | | ||||||||||||||||||||||||||||
| 344 | (?:Size="\d+(?:,\d+)?"(?{++$s{Column}->{Size}; $check->('Column.Size',1)})) | | ||||||||||||||||||||||||||||
| 345 | (?:Default=".*?"(?{++$s{Column}->{Default}; $check->('Column.Default',1)})) | ||||||||||||||||||||||||||||
| 346 | ) | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | (?<COLUMN_DROP> | ||||||||||||||||||||||||||||
| 349 | <ColumnDrop (?{delete $s{Column}}) | ||||||||||||||||||||||||||||
| 350 | ( \s+ (?&COLUMN_DROP_ATTR))+ \s* (?:/>|>\s*</ColumnDrop>) | ||||||||||||||||||||||||||||
| 351 | (*COMMIT) | ||||||||||||||||||||||||||||
| 352 | ) | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | (?<COLUMN_DROP_ATTR> | ||||||||||||||||||||||||||||
| 355 | (?:Name="[^"]+?"(?{++$s{Column}->{Name}; $check->('Column.Name',1,1)})) | ||||||||||||||||||||||||||||
| 356 | ) | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | (?<INSERT> | ||||||||||||||||||||||||||||
| 359 | <Insert (?{delete @s{map{'Insert.'. $_}qw/Table Type Version/};}) | ||||||||||||||||||||||||||||
| 360 | ( \s+ (?&INSERT_ATTR))+> | ||||||||||||||||||||||||||||
| 361 | (\s+ (?&INSERT_DATA) )+ \s* | ||||||||||||||||||||||||||||
| 362 | </Insert> | ||||||||||||||||||||||||||||
| 363 | (*COMMIT) | ||||||||||||||||||||||||||||
| 364 | ) | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | (?<INSERT_ATTR> | ||||||||||||||||||||||||||||
| 367 | (?:Table=".*?"(?{++$s{'Insert.Table'}; $check->('Insert.Table',1,1)})) | | ||||||||||||||||||||||||||||
| 368 | (?:Type=".*?"(?{++$s{'Insert.Type'}; $check->('Insert.Type',1)})) | | ||||||||||||||||||||||||||||
| 369 | (?:Version=".*?"(?{++$s{'Insert.Version'}; $check->('Insert.Version',1)})) | ||||||||||||||||||||||||||||
| 370 | ) | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | (?<INSERT_DATA> | ||||||||||||||||||||||||||||
| 373 | <Data (?{delete @s{map{'Data.'. $_}qw/Key Type Translatable/};}) | ||||||||||||||||||||||||||||
| 374 | ( \s+ (?&INSERT_DATA_ATTR))+> | ||||||||||||||||||||||||||||
| 375 | .*? | ||||||||||||||||||||||||||||
| 376 | </Data> | ||||||||||||||||||||||||||||
| 377 | (*COMMIT) | ||||||||||||||||||||||||||||
| 378 | ) | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | (?<INSERT_DATA_ATTR> | ||||||||||||||||||||||||||||
| 381 | (?:Key=".*?"(?{++$s{'Data.Key'}; $check->('Data.Key',1,1)})) | | ||||||||||||||||||||||||||||
| 382 | (?:Translatable="[01]"(?{++$s{'Data.Translatable'}; $check->('Data.Translatable',1)})) | | ||||||||||||||||||||||||||||
| 383 | (?:Type=".*?"(?{++$s{'Data.Type'}; $check->('Data.Type',1)})) | ||||||||||||||||||||||||||||
| 384 | ) | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | (?<INDEX> | ||||||||||||||||||||||||||||
| 387 | <Index ( \s+ Name=".*?")?> | ||||||||||||||||||||||||||||
| 388 | (\s+ (?&INDEX_COLUMN) )+ \s* | ||||||||||||||||||||||||||||
| 389 | </Index> | ||||||||||||||||||||||||||||
| 390 | (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 391 | (*COMMIT) | ||||||||||||||||||||||||||||
| 392 | ) | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | (?<INDEX_CREATE> | ||||||||||||||||||||||||||||
| 395 | <IndexCreate (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 396 | ( \s* (?&NAME_ATTR))? \s* (?:/>|> | ||||||||||||||||||||||||||||
| 397 | (\s+ (?&INDEX_COLUMN) )* \s* | ||||||||||||||||||||||||||||
| 398 | </IndexCreate>) | ||||||||||||||||||||||||||||
| 399 | (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 400 | (*COMMIT) | ||||||||||||||||||||||||||||
| 401 | ) | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | (?<INDEX_COLUMN> | ||||||||||||||||||||||||||||
| 404 | <IndexColumn (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 405 | ( \s* (?&NAME_OR_SIZE_ATTR))* \s* (?:/>|>\s*</IndexColumn>) | ||||||||||||||||||||||||||||
| 406 | (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 407 | (*COMMIT) | ||||||||||||||||||||||||||||
| 408 | ) | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | (?<NAME_OR_SIZE_ATTR> | ||||||||||||||||||||||||||||
| 411 | (?&NAME_ATTR) | | ||||||||||||||||||||||||||||
| 412 | (?:Size="[^"]*") | ||||||||||||||||||||||||||||
| 413 | ) | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | (?<INDEX_DROP> | ||||||||||||||||||||||||||||
| 416 | <IndexDrop (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 417 | ( \s* (?&NAME_ATTR))? \s* (?:/>|>\s*</IndexDrop>) | ||||||||||||||||||||||||||||
| 418 | (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 419 | (*COMMIT) | ||||||||||||||||||||||||||||
| 420 | ) | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | (?<UNIQUE> | ||||||||||||||||||||||||||||
| 423 | <Unique ( \s+ Name=".*?")?> | ||||||||||||||||||||||||||||
| 424 | (\s+ (?&UNIQUE_COLUMN) )+ \s* | ||||||||||||||||||||||||||||
| 425 | </Unique> | ||||||||||||||||||||||||||||
| 426 | (*COMMIT) | ||||||||||||||||||||||||||||
| 427 | ) | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | (?<UNIQUE_COLUMN> | ||||||||||||||||||||||||||||
| 430 | <UniqueColumn (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 431 | ( \s+ (?&NAME_ATTR))? \s* (?:/>|>\s*</UniqueColumn>) | ||||||||||||||||||||||||||||
| 432 | (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 433 | (*COMMIT) | ||||||||||||||||||||||||||||
| 434 | ) | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | (?<UNIQUE_CREATE> | ||||||||||||||||||||||||||||
| 437 | <UniqueCreate (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 438 | ( \s+ (?&NAME_ATTR))? \s* (?:/>|>\s*</UniqueCreate>) | ||||||||||||||||||||||||||||
| 439 | (?{ delete $s{'Generic.Name'}; }) | ||||||||||||||||||||||||||||
| 440 | (*COMMIT) | ||||||||||||||||||||||||||||
| 441 | ) | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | (?<UNIQUE_DROP> | ||||||||||||||||||||||||||||
| 444 | <UniqueDrop ( \s+ Name="[^"]+")? \s* (?:/>|>\s*</UniqueDrop>) | ||||||||||||||||||||||||||||
| 445 | (*COMMIT) | ||||||||||||||||||||||||||||
| 446 | ) | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | (?<NAME_ATTR> | ||||||||||||||||||||||||||||
| 449 | (?:Name="[^"]+"(?{++$s{'Generic.Name'}; $check->('Generic.Name',1,1)})) | ||||||||||||||||||||||||||||
| 450 | ) | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | (?<FOREIGN_KEY> | ||||||||||||||||||||||||||||
| 453 | <ForeignKey (?{delete $s{'ForeignTable'};}) (?: \s+ (?&FOREIGN_TABLE) )+> | ||||||||||||||||||||||||||||
| 454 | (\s+ (?&REFERENCE) )+ \s* | ||||||||||||||||||||||||||||
| 455 | </ForeignKey> | ||||||||||||||||||||||||||||
| 456 | (*COMMIT) | ||||||||||||||||||||||||||||
| 457 | ) | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | (?<FOREIGN_KEY_CREATE> | ||||||||||||||||||||||||||||
| 460 | <ForeignKeyCreate (?{ delete $s{'ForeignTable'}; }) | ||||||||||||||||||||||||||||
| 461 | (?: \s+ (?:(?&NAME_ATTR)|(?&FOREIGN_TABLE)))? \s* (?:/>|>\s* | ||||||||||||||||||||||||||||
| 462 | (\s+ (?&REFERENCE) )* \s* | ||||||||||||||||||||||||||||
| 463 | </ForeignKeyCreate>) | ||||||||||||||||||||||||||||
| 464 | (*COMMIT) | ||||||||||||||||||||||||||||
| 465 | ) | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | (?<FOREIGN_KEY_DROP> | ||||||||||||||||||||||||||||
| 468 | <ForeignKeyDrop ( \s+ (?:Name|ForeignTable)="[^"]+")? \s* (?:/>|>\s*(?:(?&REFERENCE)\s*)*</ForeignKeyDrop>) | ||||||||||||||||||||||||||||
| 469 | (*COMMIT) | ||||||||||||||||||||||||||||
| 470 | ) | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | (?<FOREIGN_TABLE> | ||||||||||||||||||||||||||||
| 473 | (?:ForeignTable="[^"]+"(?{++$s{'ForeignTable'}; $check->('ForeignTable',1,1)})) | ||||||||||||||||||||||||||||
| 474 | ) | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | (?<REFERENCE> | ||||||||||||||||||||||||||||
| 477 | <Reference (?{ delete @s{qw/Reference.Local Reference.Foreign/}; }) | ||||||||||||||||||||||||||||
| 478 | ( \s+ (?&REFERENCE_ATTR) )+ \s* | ||||||||||||||||||||||||||||
| 479 | (?:\s*/>|>\s*</Reference>) | ||||||||||||||||||||||||||||
| 480 | (*COMMIT) | ||||||||||||||||||||||||||||
| 481 | ) | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | (?<REFERENCE_ATTR> | ||||||||||||||||||||||||||||
| 484 | (?:Local="[^"]+"(?{++$s{'Reference.Local'}; $check->('Reference.Local',1,1)})) | | ||||||||||||||||||||||||||||
| 485 | (?:Foreign="[^"]+"(?{++$s{'Reference.Foreign'}; $check->('Reference.Foreign',1,1)})) | ||||||||||||||||||||||||||||
| 486 | ) | ||||||||||||||||||||||||||||
| 487 | ) | ||||||||||||||||||||||||||||
| 488 | 21 | }xms; | |||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 21 | return $check, $grammar; | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 2 | 1; | |||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | __END__ | ||||||||||||||||||||||||||||