Chart::OFC::Role::OFCDataLines - helper for classes which generate OFC data


Chart-OFC documentation Contained in the Chart-OFC distribution.

Index


Code Index:

NAME

Top

Chart::OFC::Role::OFCDataLines - helper for classes which generate OFC data

VERSION

Top

version 0.10

SYNOPSIS

Top

  package Chart::OFC;

  use MooseX::StrictConstructor;

  with 'Chart::OFC::Role::OFCDataLines';

DESCRIPTION

Top

This class provides a common helper method for classes which generate OFC data (which is most classes in the Chart::OFC distro).

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


Chart-OFC documentation Contained in the Chart-OFC distribution.

package Chart::OFC::Role::OFCDataLines;
BEGIN {
  $Chart::OFC::Role::OFCDataLines::VERSION = '0.10';
}

use strict;
use warnings;

use Moose::Role;

requires '_ofc_data_lines';

sub _data_line    ## no critic RequireArgUnpacking
{
    my $self  = shift;
    my $label = shift;
    my @vals  = @_;

    $label =~ s/color/colour/;

    my $line = q{&} . $label . q{=};

    $line .=
        join ',', map { $self->_format_value($_) } @vals;

    $line .= q{&};

    return $line;
}

sub _format_value
{
    my $self  = shift;
    my $value = shift;

    return 'null' unless defined $value;

    # nested array ref values attr for things like scatter charts
    if ( ref $value eq 'ARRAY' )
    {
        return '[' . ( join ',', @{ $value } ) . ']';
    }
    else
    {
        return $self->_escape($value);
    }
}

sub _escape
{
    shift;
    my $string = shift;

    $string =~ s/,/#comma#/g;

    return $string;
}

no Moose::Role;

1;

# ABSTRACT: helper for classes which generate OFC data




__END__