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::JSON->new(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.
- $class->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 file in JSON serialization. Improves base, see "Actions" in Math::Formula::Config
-Option --Default filename <directory/$name.json>
- $obj->save($context, %options)
-
Serialize the
$context
to JSON files, as storage or to be edited by hand. This is a useful method when default configuration templates need to be generated. Improves base, see "Actions" in Math::Formula::Config-Option --Default filename $context->name .json
DETAILS
JSON seems to be everyone's favorite 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 }
DIAGNOSTICS
- Fault: Error on close while saving '$name' to $file: $!
- Error: Save directory '$dir' does not exist
- Error: Save directory required
- Fault: Trying to save context '$name' to $file: $!
- Warning: cannot (yet) save CODE, skipped '$name'
SEE ALSO
This module is part of Math-Formula version 0.17, built on August 17, 2025. Website: http://perl.overmeer.net/CPAN/
LICENSE
For contributors see file ChangeLog.
This software is copyright (c) 2023-2025 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.