line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TOML::Tiny::Util; |
2
|
|
|
|
|
|
|
# ABSTRACT: utility functions used by TOML::Tiny |
3
|
|
|
|
|
|
|
$TOML::Tiny::Util::VERSION = '0.16'; |
4
|
285
|
|
|
285
|
|
2065
|
use strict; |
|
285
|
|
|
|
|
619
|
|
|
285
|
|
|
|
|
8274
|
|
5
|
285
|
|
|
285
|
|
1521
|
use warnings; |
|
285
|
|
|
|
|
4787
|
|
|
285
|
|
|
|
|
8420
|
|
6
|
285
|
|
|
285
|
|
1866
|
no warnings 'experimental'; |
|
285
|
|
|
|
|
768
|
|
|
285
|
|
|
|
|
9006
|
|
7
|
285
|
|
|
285
|
|
3775
|
use v5.18; |
|
285
|
|
|
|
|
1143
|
|
8
|
|
|
|
|
|
|
|
9
|
285
|
|
|
285
|
|
2060
|
use TOML::Tiny::Grammar; |
|
285
|
|
|
|
|
786
|
|
|
285
|
|
|
|
|
66708
|
|
10
|
|
|
|
|
|
|
|
11
|
285
|
|
|
285
|
|
2259
|
use parent 'Exporter'; |
|
285
|
|
|
|
|
700
|
|
|
285
|
|
|
|
|
2372
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
is_strict_array |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my @_type_map = ( |
18
|
|
|
|
|
|
|
[ qr{Float}, 'float' ], |
19
|
|
|
|
|
|
|
[ qr{Int}, 'integer' ], |
20
|
|
|
|
|
|
|
[ qr{Boolean}, 'bool' ], |
21
|
|
|
|
|
|
|
[ qr{^$Boolean}, 'bool' ], |
22
|
|
|
|
|
|
|
[ qr{^$Float}, 'float' ], |
23
|
|
|
|
|
|
|
[ qr{^$Integer}, 'integer' ], |
24
|
|
|
|
|
|
|
[ qr{^$DateTime}, 'float' ], |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub is_strict_array { |
28
|
1
|
|
|
1
|
0
|
3
|
my $arr = shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @types = map{ |
31
|
1
|
|
|
|
|
3
|
my $value = $_; |
|
1
|
|
|
|
|
2
|
|
32
|
1
|
|
|
|
|
2
|
my $type; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
my $ref = ref($value); |
35
|
1
|
50
|
|
|
|
4
|
if ($ref eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
36
|
1
|
|
|
|
|
3
|
$type = 'array'; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($ref eq 'HASH') { |
39
|
0
|
|
|
|
|
0
|
$type = 'table'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
# Do a little heuristic guess-work |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
0
|
for my $pair (@_type_map) { |
44
|
0
|
0
|
|
|
|
0
|
if ( $ref =~ m{$pair->[0]} ) { |
45
|
0
|
|
|
|
|
0
|
$type = $pair->[1]; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
0
|
last; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
50
|
|
|
3
|
$type //= 'string'; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
return $type; |
53
|
|
|
|
|
|
|
} @$arr; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $t = shift @types; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
for (@types) { |
58
|
0
|
0
|
|
|
|
|
return (undef, "expected value of type $t, but found $_") |
59
|
|
|
|
|
|
|
if $_ ne $t; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return (1, undef); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding UTF-8 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
TOML::Tiny::Util - utility functions used by TOML::Tiny |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 VERSION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
version 0.16 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Jeff Ober <sysread@fastmail.fm> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Jeff Ober. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
90
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |