NAME
Math::Formula::Config::YAML - load/save formulas to file in YAML
INHERITANCE
Math::Formula::Config::YAML
is a Math::Formula::Config
SYNOPSIS
my $context = Math::Formula::Content->new(name => 'test');
my $config = Math::Formula::Config::YAML->new(directory => $dir);
$config->save($context);
my $context = $config->load('test');
DESCRIPTION
Write a Context to file, and read it back again.
The attributes, formulas, and fragments are written as three separate documents.
You need to have installed YAML::XS, minimal version 0.81 (for security reasons) and module boolean.pm
. They are 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 yml file. Improves base, see "Actions" in Math::Formula::Config
-Option --Default filename <directory/$name.yml>
- $obj->save($context, %options)
-
Serialize the
$context
to YAML 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 .yml
DETAILS
YAML has a super powerful syntax, which natively supports integers, floats, booleans, and strings. But it can do so much more! (What we are not gonna use (yet))
The Context's attributes are in the first document. The formulas are in the second document. The fragments will get a place in the third document (but are not yet supported).
On Perl, you will need YAML::XS to be able to treat booleans correctly. For instance, YAML.pm
will create a string with content 'true
' without quotes... which makes it a boolean.
. Example
---
created: =2023-02-27T15:54:54+0000
mf_version: ''
name: test
updated: =2023-02-27T15:54:54+0000
version: '1.00'
---
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'
---
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.18, built on August 19, 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.