| 1 | package TOML::XS; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | our ($VERSION); | |
| 7 | |||
| 8 | 1 | ▶ | use Types::Serialiser (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use XSLoader (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | BEGIN { | ||
| 13 | 1 | ▶ | $VERSION = '0.01'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 1 | XSLoader::load(); | |
| 15 | } | ||
| 16 | |||
| 17 | =encoding utf8 | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | TOML::XS - Parse L<TOML|https://toml.io> with XS | ||
| 22 | |||
| 23 | =head1 SYNOPSIS | ||
| 24 | |||
| 25 | # NB: Don’t read_text(), or stuff may break. | ||
| 26 | my $toml = File::Slurper::read_binary('/path/to/toml/file'); | ||
| 27 | |||
| 28 | my $struct = TOML::XS::from_toml($toml)->to_struct(); | ||
| 29 | |||
| 30 | =head1 DESCRIPTION | ||
| 31 | |||
| 32 | This module facilitates parsing of TOML documents in Perl via XS, | ||
| 33 | which can yield significant performance gains relative to pure-Perl TOML | ||
| 34 | libraries. | ||
| 35 | |||
| 36 | It is currently implemented as a wrapper around the | ||
| 37 | L<tomlc99|https://github.com/cktan/tomlc99> C library. | ||
| 38 | |||
| 39 | =head1 FUNCTIONS | ||
| 40 | |||
| 41 | =head2 $doc = TOML::XS::from_toml($byte_string) | ||
| 42 | |||
| 43 | Converts a byte string (i.e., raw, undecoded bytes) that contains a | ||
| 44 | serialized TOML document to a L<TOML::XS::Document> instance. | ||
| 45 | |||
| 46 | =head1 MAPPING TOML TO PERL | ||
| 47 | |||
| 48 | Most TOML data items map naturally to Perl. The following details | ||
| 49 | are relevant: | ||
| 50 | |||
| 51 | =over | ||
| 52 | |||
| 53 | =item * Strings are character-decoded. | ||
| 54 | |||
| 55 | =item * Booleans are represented as L<TOML::XS::true> and L<TOML::XS::false>, | ||
| 56 | which are namespace aliases for the relevant constants from | ||
| 57 | L<Types::Serialiser>. | ||
| 58 | |||
| 59 | =item * Timestamps are represented as L<TOML::XS::Timestamp> instances. | ||
| 60 | |||
| 61 | =back | ||
| 62 | |||
| 63 | =head1 NOTE ON CHARACTER DECODING | ||
| 64 | |||
| 65 | This library mimics the default configuration of popular JSON modules: | ||
| 66 | the TOML input to the parser is expected to be a byte string, while the | ||
| 67 | strings that the parser outputs are character strings. | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | #---------------------------------------------------------------------- | ||
| 72 | |||
| 73 | 1 | *true = *Types::Serialiser::true; | |
| 74 | 1 | *false = *Types::Serialiser::false; | |
| 75 | |||
| 76 | #---------------------------------------------------------------------- | ||
| 77 | |||
| 78 | =head1 PERFORMANCE | ||
| 79 | |||
| 80 | For small- and medium-sized files this should be quite a bit faster | ||
| 81 | than pure-Perl TOML parsers. With larger files the speed gains are more | ||
| 82 | muted or even (??) reversed. (That’s an underlying issue with tomlc99.) | ||
| 83 | |||
| 84 | =head1 COPYRIGHT & LICENSE | ||
| 85 | |||
| 86 | Copyright 2021 Gasper Software Consulting. All rights reserved. | ||
| 87 | |||
| 88 | This library is licensed under the same license as Perl itself. | ||
| 89 | |||
| 90 | L<tomlc99|https://github.com/cktan/tomlc99> is licensed under the | ||
| 91 | L<MIT License|https://mit-license.org/>. | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | 1 | 1; | |