App-CSV2Chart

 view release on metacpan or  search on metacpan

lib/App/CSV2Chart/Command/svg.pm  view on Meta::CPAN

use warnings;
use 5.014;

use App::CSV2Chart -command;
use App::CSV2Chart::API::ToXLSX ();

use Path::Tiny qw/ path tempdir tempfile cwd /;

sub description
{
    return "Generate .svg";
}

sub abstract
{
    return shift->description();
}

sub opt_spec
{
    return @{ App::CSV2Chart::API::ToXLSX::_to_xlsx_common_opt_spec() };
}

sub execute
{
    my ( $self, $opt, $args ) = @_;

    my $output_fn = delete $opt->{output};
    my $exe       = delete( $opt->{exec} ) // [];

    my $fh = \*STDIN;

    my $dir = tempdir();

    if ( "$dir" =~ /%/ )
    {
        die "Invalid dir path $dir contains percent signs";
    }

    my $xlsx = $dir->child("temp.xlsx");

    App::CSV2Chart::API::ToXLSX::csv_to_xlsx(
        {
            input_fh  => $fh,
            output_fn => "$xlsx",
            %$opt,
        }
    );

    my $svg_fn = $dir->child("out%.svg");
    if (
        system(
            "ssconvert", "--export-graphs",
            "$xlsx", ( "$svg_fn" =~ s/%/%%/r )
        )
        )
    {
        die "ssconvert failed";
    }

    # Use ->copy instead of ->move because rename does
    # not handle cross-partition moves.
    $svg_fn->copy($output_fn);

    if (@$exe)
    {
        system( @$exe, $output_fn );
    }

    return;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

csv2chart svg - generate an .svg file of a chart from CSV data (requires a recent version of
gnumeric's ssconvert utility).

=head1 VERSION

version 0.12.0

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/App-CSV2Chart>

=item *

RT: CPAN's Bug Tracker

The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.

L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-CSV2Chart>

=item *

CPANTS

The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.



( run in 0.603 second using v1.01-cache-2.11-cpan-39bf76dae61 )