TOML file parser and writer
Perl6
Latest commit a332394 Feb 7, 2017 @atweiden mv META.info META6.json
rename META.info to META6.json to be more compatible with S22 spec [1]

[1]: https://design.perl6.org/S22.html#DISTRIBUTION
Permalink
Failed to load latest commit information.
lib rm superfluous variable assignments Sep 17, 2016
t harmonize vimsig Aug 23, 2016
.travis.yml tab width 4 .travis.yml Aug 14, 2016
META6.json mv META.info META6.json Feb 7, 2017
README.md specify Crane dep, reformat Sep 5, 2016
UNLICENSE Initial import Oct 1, 2015

README.md

Config::TOML

TOML file parser and writer.

Usage

TOML to Perl6:

use Config::TOML;

# parse toml from string
my $toml = Q:to/EOF/;
[server]
host = "192.168.1.1"
ports = [ 8001, 8002, 8003 ]
EOF
my %toml = from-toml($toml);

# parse toml from file
my $file = 'config.toml';
my %toml = from-toml(:$file);

Perl6 to TOML:

use Config::TOML;
my %h = :a<alpha>, :b<bravo>, :c<charlie>;
to-toml(%h);

Advanced Usage

Specifying a custom local offset for TOML date values

TOML date values can take three different forms:

  1. RFC 3339 timestamps (YYYY-MM-ddThh:mm:ss.ffff+zz)
  2. RFC 3339 timestamps with the local offset omitted (YYYY-MM-ddThh:mm:ss.ffff)
  3. Standard calendar dates (YYYY-MM-dd)

Config::TOML builds Perl6 Dates from standard calendar dates.

By default, Config::TOML builds Perl6 DateTimes from TOML datetime values that do not include a local offset using the host machine's local offset. To override the default behavior of using the host machine's local offset for date values where the offset is omitted, pass the date-local-offset parameter (with an integer value) to from-toml:

my $cfg = slurp 'config.toml';

# assume UTC when local offset unspecified in TOML dates
my %toml = from-toml($cfg, :date-local-offset(0));

To calculate a target timezone's local offset for the date-local-offset parameter value, multiply its UTC offset hours by 60, add to this its UTC offset minutes, and multiply the result by 60.

Timezone UTC Offset Calculation
Africa/Johannesburg UTC+02:00 ((2 * 60) + 0) * 60 = 7200
America/Los_Angeles UTC-07:00 ((-7 * 60) + 0) * 60 = -25200
Asia/Seoul UTC+09:00 ((9 * 60) + 0) * 60 = 32400
Australia/Sydney UTC+10:00 ((10 * 60) + 0) * 60 = 36000
Europe/Berlin UTC+01:00 ((1 * 60) + 0) * 60 = 3600
UTC UTC±00:00 ((0 * 60) + 0) * 60 = 0

To more easily ascertain your host machine's local offset, open a perl6 repl and print the value of $*TZ.

Installation

Dependencies

Licensing

This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.