Data-TOON

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

[![Actions Status](https://github.com/ytnobody/p5-Data-TOON/actions/workflows/test.yml/badge.svg)](https://github.com/ytnobody/p5-Data-TOON/actions)
# NAME

Data::TOON - Complete Perl implementation of TOON (Token-Oriented Object Notation)

# SYNOPSIS

    use Data::TOON;

    # Basic usage
    my $data = { name => 'Alice', age => 30, active => 1 };
    my $toon = Data::TOON->encode($data);
    print $toon;
    # Output:
    #   active: true
    #   age: 30
    #   name: Alice

    my $decoded = Data::TOON->decode($toon);
    
    # Tabular arrays
    my $users = {
        users => [
            { id => 1, name => 'Alice', role => 'admin' },
            { id => 2, name => 'Bob', role => 'user' }
        ]
    };
    
    print Data::TOON->encode($users);
    # Output:
    #   users[2]{id,name,role}:
    #     1,Alice,admin
    #     2,Bob,user

    # Alternative delimiters
    my $encoder = Data::TOON::Encoder->new(delimiter => '|');
    print $encoder->encode($users);
    # Or with tabs:
    my $tab_encoder = Data::TOON::Encoder->new(delimiter => "\t");

    # Root primitives and arrays
    print Data::TOON->encode(42);           # Output: 42
    print Data::TOON->encode('hello');      # Output: hello
    print Data::TOON->encode([1, 2, 3]);    # Output: [3]: 1,2,3

# DESCRIPTION

Data::TOON is a complete Perl implementation of TOON (Token-Oriented Object Notation), a human-friendly, 
line-oriented data serialization format.

TOON provides:

- **Human-readable syntax** - Indentation-based, similar to YAML, with minimal quoting
- **Multiple array formats** - Compact tabular, explicit list, or inline primitive arrays
- **Flexible delimiters** - Support for comma, tab, and pipe delimiters
- **Security** - DoS protection via depth limits and circular reference detection
- **Canonical numbers** - Automatic number normalization (removes trailing zeros, etc.)
- **Full TOON compliance** - 95%+ coverage of TOON specification v1.0

The format is particularly useful for configuration files, data interchange, and human-editable data storage.

# METHODS

## encode( $data, %options )

Encodes a Perl data structure to TOON format string.

**Parameters:**

- `$data`

    The Perl data structure to encode. Can be:
    \- Hash reference (becomes TOON object)
    \- Array reference (becomes TOON array)
    \- Scalar (becomes root primitive: number, string, boolean, or null)

- `%options`

    Optional encoder configuration:



( run in 1.992 second using v1.01-cache-2.11-cpan-437f7b0c052 )