Google::Chart::Title - Apply Title


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

Index


Code Index:

NAME

Top

Google::Chart::Title - Apply Title

METHODS

Top

as_query


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

# $Id$

package Google::Chart::Title;
use Moose;
use Google::Chart::Types;
use Moose::Util::TypeConstraints;

coerce 'Google::Chart::Title'
    => from 'HashRef'
    => via {
        Google::Chart::Title->new(%$_);
    }
;

with 'Google::Chart::QueryComponent';

has 'text' => (
    is => 'rw',
    isa => 'Str',
    required => 1,
);

has 'color' => (
    is => 'rw',
    isa => 'Google::Chart::Color',
);

has 'fontsize' => (
    is => 'rw',
    isa => 'Num'
);

__PACKAGE__->meta->make_immutable;

no Moose;

sub as_query {
    my $self = shift;

    my $text = $self->text;
    $text =~ s/\r?\n/|/gsm;
    my %data = (
        chtt => $text
    );

    my $color = $self->color;
    my $fontsize = $self->fontsize;
    if (defined $color || defined $fontsize) {
        $data{chts} = join(',', 
            defined $color ? $color : '',
            defined $fontsize ? $fontsize : ''
        );
    }

    return wantarray ? %data : 
        join('&', map { "$_=$data{$_}" } keys %data );
}

1;

__END__