| 1 | package TOML::Tiny::Util; | ||||||||||||||
| 2 | # ABSTRACT: utility functions used by TOML::Tiny | ||||||||||||||
| 3 | 286 | $TOML::Tiny::Util::VERSION = '0.21'; | |||||||||||||
| 4 | 286 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 286 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 286 | ▶ | no warnings 'experimental'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 286 | ▶ | use v5.18; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 286 | ▶ | use TOML::Tiny::Grammar; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 286 | ▶ | use parent 'Exporter'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 286 | our @EXPORT_OK = qw( | |||||||||||||
| 14 | is_strict_array | ||||||||||||||
| 15 | ); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 286 | 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 | 2 | ▶ | my $arr = shift; | ||||||||||||
|
Subroutine
is_strict_array: called CC=8 SCAR=23.9
Pod
undocumented
| |||||||||||||||
| 29 | |||||||||||||||
| 30 | my @types = map{ | ||||||||||||||
| 31 | 2 | my $value = $_; | |||||||||||||
| 32 | 2 | my $type; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | my $ref = ref($value); | |||||||||||||
| 35 | 2 | ▶ | if ($ref eq 'ARRAY') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | 1 | $type = 'array'; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | elsif ($ref eq 'HASH') { | ||||||||||||||
| 39 | 0 | $type = 'table'; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | # Do a little heuristic guess-work | ||||||||||||||
| 42 | else { | ||||||||||||||
| 43 | 1 | for my $pair (@_type_map) { | |||||||||||||
| 44 | 1 | ▶ | if ( $ref =~ m{$pair->[0]} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 0 | $type = $pair->[1]; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | 1 | last; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | } | ||||||||||||||
| 50 | 2 | ▶ | $type //= 'string'; | ||||||||||||
|
Condition100%2/2
$type //= "string"
MC/DC100%1/1
$type //= "string"
$type
Truth table100%2/2
A
A= $type
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | 2 | return $type; | |||||||||||||
| 53 | } @$arr; | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 0 | my $t = shift @types; | |||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | for (@types) { | |||||||||||||
| 58 | 0 | ▶ | return (undef, "expected value of type $t, but found $_") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | if $_ ne $t; | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | return (1, undef); | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 286 | 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.21 | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 AUTHOR | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Jeff Ober <sysread@fastmail.fm> | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 86 | |||||||||||||||
| 87 | This software is copyright (c) 2026 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 | ||||||||||||||