| 1 | package App::SVG::Graph; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION = 'v0.0.2'; | |||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use SVG::Graph::Kit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Getopt::Long qw( GetOptionsFromArray ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Pod::Usage; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | sub argv | ||||||||||
| 17 | 0 | ▶ | { | ||||||||
|
Subroutine
argv: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 18 | 0 | my $self = shift; | |||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | { | ||||||||||
| 22 | 0 | $self->{argv} = shift; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | return $self->{argv}; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub new | ||||||||||
| 29 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 30 | 0 | my $class = shift; | |||||||||
| 31 | |||||||||||
| 32 | 0 | my $self = bless {}, $class; | |||||||||
| 33 | |||||||||||
| 34 | 0 | $self->_init(@_); | |||||||||
| 35 | |||||||||||
| 36 | 0 | return $self; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub _init | ||||||||||
| 40 | 0 | ▶ | { | ||||||||
|
Subroutine
_init: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | my ( $self, $args ) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 0 | $self->argv( $args->{argv} ); | |||||||||
| 44 | |||||||||||
| 45 | 0 | return; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | sub _slurp_lines | ||||||||||
| 49 | 0 | ▶ | { | ||||||||
|
Subroutine
_slurp_lines: not called CC=1 SCAR=6.9
| |||||||||||
| 50 | 0 | my $in = shift; | |||||||||
| 51 | |||||||||||
| 52 | 0 | my @ret = <$in>; | |||||||||
| 53 | 0 | chomp(@ret); | |||||||||
| 54 | |||||||||||
| 55 | 0 | return \@ret; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | sub _render_as_svg | ||||||||||
| 59 | 0 | ▶ | { | ||||||||
|
Subroutine
_render_as_svg: not called CC=1 SCAR=6.9
| |||||||||||
| 60 | 0 | my ( $self, $args ) = @_; | |||||||||
| 61 | |||||||||||
| 62 | 0 | my $g = SVG::Graph::Kit->new( data => $args->{data} ); | |||||||||
| 63 | 0 | print { $args->{out_fh} } $g->draw; | |||||||||
| 64 | |||||||||||
| 65 | 0 | return; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub run | ||||||||||
| 69 | 0 | ▶ | { | ||||||||
|
Subroutine
run: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 70 | 0 | my ($self) = @_; | |||||||||
| 71 | |||||||||||
| 72 | 0 | my $output_fn; | |||||||||
| 73 | 0 | my $man = 0; | |||||||||
| 74 | 0 | my $help = 0; | |||||||||
| 75 | 0 | my $version = 0; | |||||||||
| 76 | |||||||||||
| 77 | 0 | my @argv = @{ $self->argv }; | |||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | GetOptionsFromArray( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | \@argv, | ||||||||||
| 81 | "output|o" => \$output_fn, | ||||||||||
| 82 | "help|h" => \$help, | ||||||||||
| 83 | "man" => \$man, | ||||||||||
| 84 | "version" => \$version, | ||||||||||
| 85 | ) or pod2usage(2); | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | if ($help) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | { | ||||||||||
| 89 | 0 | pod2usage(1); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | if ($man) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | { | ||||||||||
| 94 | 0 | pod2usage( -verbose => 2 ); | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | if ($version) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | { | ||||||||||
| 99 | 0 | print "svg-graph version $VERSION\n"; | |||||||||
| 100 | 0 | exit(0); | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 0 | my $in_fh; | |||||||||
| 104 | |||||||||||
| 105 | 0 | my $filename = shift(@argv); | |||||||||
| 106 | 0 | ▶ | if ( !defined($filename) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | { | ||||||||||
| 108 | 0 | $in_fh = \*STDIN; | |||||||||
| 109 | } | ||||||||||
| 110 | else | ||||||||||
| 111 | { | ||||||||||
| 112 | 0 | open $in_fh, '<', $filename; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | 0 | my $out_fh; | |||||||||
| 116 | |||||||||||
| 117 | 0 | ▶ | if ( !defined($output_fn) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | { | ||||||||||
| 119 | 0 | $out_fh = \*STDOUT; | |||||||||
| 120 | } | ||||||||||
| 121 | else | ||||||||||
| 122 | { | ||||||||||
| 123 | 0 | open $out_fh, '>', $output_fn; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 0 | my $data = [ map { [ split /\t/, $_ ] } @{ _slurp_lines($in_fh) } ]; | |||||||||
| 127 | 0 | $self->_render_as_svg( { data => $data, out_fh => $out_fh } ); | |||||||||
| 128 | |||||||||||
| 129 | 0 | close($out_fh); | |||||||||
| 130 | |||||||||||
| 131 | 0 | ▶ | if ( defined($filename) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | { | ||||||||||
| 133 | 0 | close($in_fh); | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 0 | return; | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 1 | 1; | |||||||||
| 140 | |||||||||||
| 141 | __END__ | ||||||||||