script/sparkline.pl untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 22 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 104 CC 6 SCAR 30.9
CC
6
Cov
0%
parameters_from_cmdline
42.0
help_types
2.0
BEGIN
2.0
CRAP 22.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 use SVG::Sparkline;
7 use Getopt::Long;
8 use Pod::Usage;
9  
10 my $type = shift;
11 if( !defined $type or $type eq '--help-types' )
12 {
13 print "No Sparkline type specified.\n";
14 help_types();
15 }
16  
17 pod2usage( -verbose => 2, -exitval => 0 )
18 if $type eq '--help' or $type eq '--man';
19  
20 my %options;
21 GetOptions(
22 'allns' => \$options{'-allns'},
23 'sized!' => \$options{'-sized'},
24 'bgcolor|bg=s' => \$options{'bgcolor'},
25 'padx=f' => \$options{'padx'},
26 'pady=f' => \$options{'pady'},
27 'height|h=f' => \$options{'height'},
28 'width|w=f' => \$options{'width'},
29 'values|v=s' => \$options{'values'},
30 'mark=s@' => \$options{'mark'},
31 'color=s' => \$options{'color'},
32 'xscale=f' => \$options{'xscale'},
33 'thick=f' => \$options{'thick'},
34 'gap=f' => \$options{'gap'},
35 'outfile|o=s' => \$options{'outfile'},
36 'clobber|c' => \$options{'clobber'},
37 'help|man' => \$options{'help'},
38 'help-types' => \$options{'help-types'},
39 ) or pod2usage( 'Unrecognized argument' );
40  
41 pod2usage( -verbose => 2, -exitval => 0 ) if $options{'help'};
42 help_types() if $options{'help-types'};
43  
44 my $svg = SVG::Sparkline->new( $type => parameters_from_cmdline( \%options ) );
45  
46 my $fh = \*STDOUT;
47 if( defined $options{'outfile'} )
48 {
49 my ($outfile,$clobber) = @options{'outfile','clobber'};
50  
51 die "Output file '$outfile' exists, failing.\n" if !$clobber and -e $outfile;
52 open( $fh, '>', $outfile ) or die "Unable to create '$outfile': $!\n";
53 }
54  
55 print $fh "$svg";
56  
57 close $fh;
58  
59 sub help_types
60 {
61 print <<'EOF';
62 Supported Sparkline types:
63  
64 * Area
65 * Bar
66 * Line
67 * RangeArea
68 * RangeBar
69 * Whisker
70  
71 Check the help page for descriptions of the types and further information.
72 EOF
73 exit;
74 }
75  
76 sub parameters_from_cmdline
77 {
78 my %params;
79  
80 die "Missing required --values parameter. No idea what to chart.\n"
81 unless defined $options{'values'};
82  
83 foreach my $key (keys %options)
84 {
85 $params{$key} = $options{$key} || 0 if $key eq '-sized';
86 $params{$key} = $options{$key} if defined $options{$key};
87 }
88 # Clean up values parameter
89
90 $params{'values'} = [ split ',', $params{'values'} ]
91 unless 'Whisker' eq $type && $params{'values'} =~ /^[-+0]+$/;
92 $params{'values'} = [ map { [ split ':', $_ ] } @{$params{'values'}} ]
93 if $type eq 'RangeArea' or $type eq 'RangeBar';
94  
95 # Clean up mark parameter
96 $params{'mark'} = [ map { split /[=:]/, $_ } @{$params{'mark'}} ];
97  
98 return \%params;
99 }
100  
101 __END__