NAME

Math::Formula::Config::JSON - load/save formulas to file

INHERITANCE

Math::Formula::Config::JSON
  is a Math::Formula::Config

SYNOPSIS

my $context = Math::Formula::Content->new(name => 'test');
my $config = Math::Formula::Config::INI->JSON(directory => $dir);

$config->save($context);
my $context = $config->load('test');

DESCRIPTION

Save and load a Math::Formula::Context to JSON files.

You need to have installed Cpanel::JSON::XS. That module is not in the dependencies of this packages, because we do not want to add complications to the main code.

Extends "DESCRIPTION" in Math::Formula::Config.

METHODS

Extends "METHODS" in Math::Formula::Config.

Constructors

Extends "Constructors" in Math::Formula::Config.

Math::Formula::Config::JSON->new(%options)

Inherited, see "Constructors" in Math::Formula::Config

Attributes

Extends "Attributes" in Math::Formula::Config.

$obj->directory()

Inherited, see "Attributes" in Math::Formula::Config

$obj->path_for($file)

Inherited, see "Attributes" in Math::Formula::Config

Actions

Extends "Actions" in Math::Formula::Config.

$obj->load($name, %options)

Load a Math::Formula::Context for a yml file.

-Option  --Default
 filename  <directory/$name.yml>
filename => FILENAME
$obj->save($context, %args)

Serialize the $context to JSON files, as storage or to be editted by hand. This is a usefull method when default configuration templates need to be generated.

-Option  --Default
 filename  C<< $context->name .json>
filename => STRING

Save under a different filename than derived from the name of the context.

DETAILS

JSON seems to be everyone's favorit serialization syntax, nowadays. It natively supports integers, floats, booleans, and strings. Formulas get a leading '=' (not yet configurable).

. Example

{ "created" : "2023-02-28T16:30:27+0000", "formulas" : { "expr1" : "=1 + 2 * 3", "expr2" : "=\"abc\".size + 3k; returns='MF::INTEGER'", "fakes" : false, "float" : 3.14, "int" : 42, "longer" : "abc def yes no", "no_quotes" : "abc", "some_truth" : true, "string" : "true" }, "mf_version" : "", "name" : "test", "updated" : "2023-02-28T16:30:27+0000", "version" : 1.0 }

SEE ALSO

This module is part of Math-Formula distribution version 0.15, built on March 06, 2023. Website: http://perl.overmeer.net/CPAN/

LICENSE

Copyrights 2023 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/