| File: | lib/OpenAPI/Util.pm |
| Coverage: | 83.3% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package OpenAPI; | ||||||
| 2 | |||||||
| 3 | 22 22 22 | 193 76 277 | use strict; | ||||
| 4 | 22 22 22 | 250 96 259 | use warnings; | ||||
| 5 | 22 22 22 | 252 72 435 | use vars qw($Backend); | ||||
| 6 | |||||||
| 7 | sub Q (@) { | ||||||
| 8 | 4284 | 0 | 33406 | if (@_ == 1) { | |||
| 9 | 4168 | 35053 | return $Backend->quote($_[0]); | ||||
| 10 | } else { | ||||||
| 11 | 116 410 | 583 2604 | return map { $Backend->quote($_) } @_; | ||||
| 12 | } | ||||||
| 13 | } | ||||||
| 14 | |||||||
| 15 | sub QI (@) { | ||||||
| 16 | 534 | 0 | 6144 | if (@_ == 1) { | |||
| 17 | 435 | 3995 | return $Backend->quote_identifier($_[0]); | ||||
| 18 | } else { | ||||||
| 19 | 99 323 | 519 24211 | return map { $Backend->quote_identifier($_) } @_; | ||||
| 20 | } | ||||||
| 21 | } | ||||||
| 22 | |||||||
| 23 | sub check_password { | ||||||
| 24 | 12 | 0 | 71 | my $password = shift; | |||
| 25 | 12 | 84 | if (!defined $password) { | ||||
| 26 | 0 | 0 | die "No password specified.\n"; | ||||
| 27 | } | ||||||
| 28 | 12 | 96 | if (length($password) < $PASSWORD_MIN_LEN) { | ||||
| 29 | 1 | 5 | die "Password too short; at least $PASSWORD_MIN_LEN chars are required.\n"; | ||||
| 30 | } | ||||||
| 31 | 11 | 165 | if ($password !~ /^[_A-Za-z0-9]+$/) { | ||||
| 32 | 0 | 0 | die "Invalid password; only underscores, letters, and digits are allowed.\n"; | ||||
| 33 | } | ||||||
| 34 | } | ||||||
| 35 | |||||||
| 36 | sub slurp { | ||||||
| 37 | 1 | 0 | 7 | my ($file) = @_; | |||
| 38 | 1 | 63 | open my $in, $file or die "Can't oepn $file for reading: $!\n"; | ||||
| 39 | 1 1 1 | 4 7 50 | my $s = do { local $/; <$in> }; | ||||
| 40 | 1 | 12 | close $in; | ||||
| 41 | 1 | 4 | $s; | ||||
| 42 | } | ||||||
| 43 | |||||||
| 44 | 1; | ||||||
| 45 | |||||||