| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: comb-svg | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Render Kubernetes::Comb custom resources from JSON as an SVG honeycomb | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 94 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 94 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 94 | ▶ | use Getopt::Long qw( GetOptionsFromArray ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 94 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 94 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 94 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 94 | ▶ | use Kubernetes::Comb::SVG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 94 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 94 | my $ME = 'comb-svg'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 62 | ▶ | sub svg_class { 'Kubernetes::Comb::SVG' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svg_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | return join( "\n", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'Usage: '.$ME.' [options] [FILE|-]', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'Reads Comb custom resources as JSON (a List, an array or one resource)', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'from FILE or standard input and writes the SVG to standard output.', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ' --title TEXT heading and <title> of the picture', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ' --group-label KEY label key whose value names the group of a Comb', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ' --layout NAME depth (rows by dependency, the default) or packed', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ' --columns N cells per row before a row wraps', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ' --rows N packed: number of rows, without --columns', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ' --aspect W:H packed: target shape, without --columns and --rows', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ' --size N radius of a hexagon in SVG units', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ' --no-edges leave out the dependency edges (--edges draws them)', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ' --no-legend leave out the legend', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ' --color KEY=COLOUR colour of a phase, @group, Phase@group or bg, fg, muted,', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ' border, edge;', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ' KEY=LIGHT,DARK for the two modes; repeatable', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ' --blink PHASES phases (or @group, Phase@group) that pulse, comma-separated', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ' --blink-seconds N period of the pulse in seconds', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ' --help this text', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ' --version the version', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | '' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # One line on stderr, nothing on stdout, exit 1 — for usage and data alike. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 31 | ▶ | sub fail { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 31 | my ( $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 31 | $message =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 31 | $message =~ s/\s*\n\s*/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 31 | print STDERR $ME.': '.$message."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 31 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # What an exception says, without where it was thrown. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | ▶ | sub reason { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reason: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | my ( $error ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | $error = ''.$error; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | $error =~ s/\A(.*) at \S.*? line \d+\.?\s*\z/$1/s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | return $error; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 94 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=25 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 94 | my ( $argv ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 94 | my %opt = ( legend => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 94 | my @complaints; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 94 | Getopt::Long::Configure(qw( no_ignore_case no_auto_abbrev )); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 94 | my $ok = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 94 | ▶ | local $SIG{__WARN__} = sub { push @complaints, @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 94 | GetOptionsFromArray( $argv, \%opt, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 'title=s', 'group-label=s', 'layout=s', 'columns=s', 'rows=s', 'aspect=s', 'size=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 'edges!', 'legend!', 'color=s@', 'blink=s@', 'blink-seconds=s', 'help', 'version' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 94 | ▶ | fail( ( @complaints ? $complaints[0] : 'bad options' ).' (try --help)' ) unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 91 | ▶ | return \%opt if $opt{help} || $opt{version}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt{"help"} or $opt{"version"}
MC/DC100%2/2
$opt{"help"} or $opt{"version"}
$opt{"help"}
$opt{"version"}
Truth table100%3/3
A or B
A= $opt{"help"}B= $opt{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | fail( '--columns needs a positive integer, got "'.$opt{columns}.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 89 | ▶ | if defined $opt{columns} && $opt{columns} !~ /\A[1-9][0-9]{0,8}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opt{"columns"} and not $opt{"columns"} =~ /\A[1-9][0-9]{0,8}\z/
MC/DC100%2/2
defined $opt{"columns"} and not $opt{"columns"} =~ /\A[1-9][0-9]{0,8}\z/
defined $opt{"columns"}
not $opt{"columns"} =~ /\A[1-9][0-9]{0,8}\z/
Truth table100%3/3
A and not(B)
A= defined $opt{"columns"}B= not $opt{"columns"} =~ /\A[1-9][0-9]{0,8}\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | fail( '--layout needs depth or packed, got "'.$opt{layout}.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 86 | ▶ | if defined $opt{layout} && $opt{layout} !~ /\A(?:depth|packed)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opt{"layout"} and not $opt{"layout"} =~ /\A(?:depth|packed)\z/
MC/DC100%2/2
defined $opt{"layout"} and not $opt{"layout"} =~ /\A(?:depth|packed)\z/
defined $opt{"layout"}
not $opt{"layout"} =~ /\A(?:depth|packed)\z/
Truth table100%3/3
A and not(B)
A= defined $opt{"layout"}B= not $opt{"layout"} =~ /\A(?:depth|packed)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | fail( '--rows needs a positive integer, got "'.$opt{rows}.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 85 | ▶ | if defined $opt{rows} && $opt{rows} !~ /\A[1-9][0-9]{0,8}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opt{"rows"} and not $opt{"rows"} =~ /\A[1-9][0-9]{0,8}\z/
MC/DC100%2/2
defined $opt{"rows"} and not $opt{"rows"} =~ /\A[1-9][0-9]{0,8}\z/
defined $opt{"rows"}
not $opt{"rows"} =~ /\A[1-9][0-9]{0,8}\z/
Truth table100%3/3
A and not(B)
A= defined $opt{"rows"}B= not $opt{"rows"} =~ /\A[1-9][0-9]{0,8}\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 83 | ▶ | if ( defined $opt{aspect} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | my $number = qr/[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9}/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | my ( $width, $height ) = $opt{aspect} =~ m{\A($number)(?:[:/]($number))?\z}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | ▶ | $height = 1 unless defined $height; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | fail( '--aspect needs a positive number or W:H, got "'.$opt{aspect}.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $width and $width > 0 and $height > 0
defined $width and $width > 0
MC/DC100%3/3
defined $width and $width > 0 and $height > 0
defined $width
$width > 0
$height > 0
Truth table100%4/4
A and B and C
A= defined $widthB= $width > 0C= $height > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | unless defined $width && $width > 0 && $height > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | $opt{aspect} = $width / $height; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | fail( '--size needs a positive number, got "'.$opt{size}.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | if defined $opt{size} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 79 | ▶ | && !( $opt{size} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{size} > 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $opt{"size"} and not $opt{"size"} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{"size"} > 0
$opt{'size'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{'size'} > 0
MC/DC100%3/3
defined $opt{"size"} and not $opt{"size"} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{"size"} > 0
defined $opt{"size"}
$opt{'size'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/
$opt{'size'} > 0
Truth table100%4/4
A and not(B && C)
A= defined $opt{"size"}B= $opt{'size'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/C= $opt{'size'} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | fail( '--blink-seconds needs a positive number, got "'.$opt{'blink-seconds'}.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | if defined $opt{'blink-seconds'} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | && !( $opt{'blink-seconds'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 77 | ▶ | && $opt{'blink-seconds'} > 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $opt{"blink-seconds"} and not $opt{"blink-seconds"} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{"blink-seconds"} > 0
$opt{'blink-seconds'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{'blink-seconds'} > 0
MC/DC100%3/3
defined $opt{"blink-seconds"} and not $opt{"blink-seconds"} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/ && $opt{"blink-seconds"} > 0
defined $opt{"blink-seconds"}
$opt{'blink-seconds'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/
$opt{'blink-seconds'} > 0
Truth table100%4/4
A and not(B && C)
A= defined $opt{"blink-seconds"}B= $opt{'blink-seconds'} =~ /\A(?:[0-9]{1,9}(?:\.[0-9]{1,9})?|\.[0-9]{1,9})\z/C= $opt{'blink-seconds'} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 73 | ▶ | $opt{blink} = [ grep { length } map { split /,/ } @{ $opt{blink} } ] if $opt{blink}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 73 | ▶ | $opt{theme} = theme( $opt{color} ) if $opt{color}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 69 | ▶ | fail( 'more than one input file (try --help)' ) if @$argv > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 68 | return \%opt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # The --color values as a theme: KEY=COLOUR, or KEY=LIGHT,DARK with the comma | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # outside parentheses, so rgb(1,2,3) stays one colour. Whether a key or a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # colour is one the picture knows is left to the module, which ignores what | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # it does not accept; the last --color of a key wins. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 19 | ▶ | sub theme { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
theme: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 19 | my ( $colors ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 19 | my %theme; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 19 | for my $color (@$colors) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 21 | my ( $key, $value ) = $color =~ /\A([^=]+)=(.+)\z/s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 21 | ▶ | my @modes = defined $value ? split( /,(?![^(]*\))/, $value, -1 ) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 21 | ▶ | fail( '--color needs KEY=COLOUR or KEY=LIGHT,DARK, got "'.$color.'"' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@modes == 1 or @modes == 2
MC/DC100%2/2
@modes == 1 or @modes == 2
@modes == 1
@modes == 2
Truth table100%3/3
A or B
A= @modes == 1B= @modes == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | unless @modes == 1 || @modes == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 17 | ▶ | $theme{$key} = @modes == 1 ? $modes[0] : { light => $modes[0], dark => $modes[1] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 15 | return \%theme; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 68 | ▶ | sub read_input { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_input: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 68 | my ( $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 68 | ▶ | if ( !defined $file || $file eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $file or $file eq "-"
MC/DC100%2/2
not defined $file or $file eq "-"
not defined $file
$file eq "-"
Truth table100%3/3
not(A) or B
A= not defined $fileB= $file eq "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | binmode STDIN; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 5 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | my $bytes = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | return ( defined $bytes ? $bytes : '', 'standard input' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 63 | my $bytes = eval { path($file)->slurp_raw }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 63 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | fail( 'cannot read '.$file.': ' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | .( blessed $error && $error->isa('Path::Tiny::Error') ? $error->{err} : reason($error) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($error) and $error->isa("Path::Tiny::Error")
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Path::Tiny::Error")
builtin::blessed($error)
$error->isa("Path::Tiny::Error")
Truth table33%1/3
A and B
A= builtin::blessed($error)B= $error->isa("Path::Tiny::Error")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 61 | return ( $bytes, $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 94 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=19 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 94 | my @argv = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 94 | utf8::decode($_) for @argv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 94 | my $opt = options( \@argv ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 70 | ▶ | if ( $opt->{help} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | print usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 69 | ▶ | if ( $opt->{version} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | print $ME.' '.$VERSION."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 68 | my ( $bytes, $source ) = read_input( $argv[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 66 | my $combs = eval { JSON::MaybeXS->new( utf8 => 1, allow_nonref => 1 )->decode($bytes) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 66 | ▶ | fail( 'invalid JSON in '.$source.': '.reason($@) ) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 63 | ▶ | fail( $source.' is neither a List, an array of Combs nor a Comb' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $combs eq "HASH" or ref $combs eq "ARRAY"
MC/DC100%2/2
ref $combs eq "HASH" or ref $combs eq "ARRAY"
ref $combs eq "HASH"
ref $combs eq "ARRAY"
Truth table100%3/3
A or B
A= ref $combs eq "HASH"B= ref $combs eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | unless ref $combs eq 'HASH' || ref $combs eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 62 | my $svg = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | svg_class()->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | combs => $combs, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | legend => $opt->{legend}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | defined $opt->{edges} ? ( edges => $opt->{edges} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | defined $opt->{title} ? ( title => $opt->{title} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | defined $opt->{'group-label'} ? ( group_label => $opt->{'group-label'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | defined $opt->{layout} ? ( layout => $opt->{layout} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | defined $opt->{columns} ? ( columns => $opt->{columns} + 0 ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | defined $opt->{rows} ? ( rows => $opt->{rows} + 0 ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | defined $opt->{aspect} ? ( aspect => $opt->{aspect} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | defined $opt->{size} ? ( size => $opt->{size} + 0 ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | defined $opt->{theme} ? ( theme => $opt->{theme} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | defined $opt->{blink} ? ( blink => $opt->{blink} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 62 | ▶ | defined $opt->{'blink-seconds'} ? ( blink_seconds => $opt->{'blink-seconds'} + 0 ) : () | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | )->render; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 62 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $error = reason($error); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | $error =~ s/\A[\w:]+->\w+: //; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | fail($error); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 61 | print $svg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 61 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 94 | exit main(@ARGV); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||