| 1 | package BalanceOfPower::Role::Reporter; | ||||||||||||||||||||||||||||
| 2 | 11 | $BalanceOfPower::Role::Reporter::VERSION = '0.200000'; | |||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use BalanceOfPower::Utils qw( get_year_turns as_title ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | with "BalanceOfPower::Role::Logger"; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | has events => ( | ||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | 90 | ▶ | default => sub { {} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 11 | ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub register_event | ||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||
| 17 | 1841 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
register_event: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 1841 | my $event = shift; | |||||||||||||||||||||||||||
| 19 | 1841 | ▶ | my $time = $self->current_year ? $self->current_year : "START"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1841 | ▶ | $self->events({}) if(! $self->events ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 1841 | push @{$self->events->{$time}}, $event; | |||||||||||||||||||||||||||
| 23 | 1841 | $self->log("[" . $self->name . "] $event"); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | sub get_events | ||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 1676 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_events: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 1676 | my $label = shift; | |||||||||||||||||||||||||||
| 29 | 1676 | my $year = shift; | |||||||||||||||||||||||||||
| 30 | 1676 | ▶ | if($self->events && exists $self->events->{$year}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->events and exists $self->events->{$year}
MC/DC50%1/2
$self->events and exists $self->events->{$year}
$self->events
exists $self->events->{$year}
Truth table66%2/3
A and B
A= $self->eventsB= exists $self->events->{$year}
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 1535 | my @events = grep { $_ =~ /^$label/ } @{$self->events->{$year}}; | |||||||||||||||||||||||||||
| 33 | 1535 | return @events; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 141 | return (); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub print_turn_events | ||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_turn_events: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 3 | my $y = shift; | |||||||||||||||||||||||||||
| 46 | 3 | return $self->_print_turn_events($y, 1); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub print_turn_events_notitle | ||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_turn_events_notitle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 1 | my $y = shift; | |||||||||||||||||||||||||||
| 53 | 1 | return $self->_print_turn_events($y, 0); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub print_turn_events_inline_year | ||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_turn_events_inline_year: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 14 | my $y = shift; | |||||||||||||||||||||||||||
| 60 | 14 | return $self->_print_turn_events($y, 2); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub _print_turn_events | ||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_print_turn_events: called CC=10 SCAR=24.7
| |||||||||||||||||||||||||||||
| 67 | 18 | my $y = shift; | |||||||||||||||||||||||||||
| 68 | 18 | my $title = shift; | |||||||||||||||||||||||||||
| 69 | 18 | my $out = ""; | |||||||||||||||||||||||||||
| 70 | 18 | my @to_print; | |||||||||||||||||||||||||||
| 71 | 18 | ▶ | if(! $y) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $y = $self->current_year ? $self->current_year : "START"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 18 | ▶ | if($y =~ /\d\d\d\d/) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 17 | @to_print = get_year_turns($y) | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | elsif($y =~ /\d\d\d\d\/\d+/) | ||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | 0 | @to_print = ($y); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | elsif($y eq 'START') | ||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | 1 | @to_print = ('START'); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | else | ||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 0 | return ""; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 18 | foreach my $t (@to_print) | |||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 18 | ▶ | $out .= as_title($self->name . " - $t\n") if $title == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 18 | foreach my $e (@{$self->events->{$t}}) | |||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 6 | $out .= " "; | |||||||||||||||||||||||||||
| 97 | 6 | ▶ | $out .= $t . ": " if($title == 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 6 | $out .= $e . "\n"; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 18 | return $out; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | sub dump_events | ||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
dump_events: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 0 | my $io = shift; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $indent = shift || ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 108 | sub sort_start | ||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return 0 if($a eq $b); | ||||||||||||||||||||||||||
|
Subroutine
sort_start: not called CC=6 SCAR=37.4
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return -1 if($a eq 'START'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return 1 if($b eq 'START'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return 1 if($a gt $b); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return -1 if($b gt $a); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | foreach my $y (sort sort_start keys %{$self->events}) | |||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||
| 118 | 0 | print {$io} $indent . "### $y\n"; | |||||||||||||||||||||||||||
| 119 | 0 | foreach my $e (@{$self->events->{$y}}) | |||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 0 | print {$io} $indent . $e . "\n"; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | sub load_events | ||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
load_events: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 129 | 0 | my @lines = split "\n", $data; | |||||||||||||||||||||||||||
| 130 | 0 | my $year = ""; | |||||||||||||||||||||||||||
| 131 | 0 | my %events; | |||||||||||||||||||||||||||
| 132 | 0 | foreach my $l (@lines) | |||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 0 | $l =~ s/^\s//; | |||||||||||||||||||||||||||
| 135 | 0 | chomp $l; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if($l =~ /### (.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | 0 | $year = $1; | |||||||||||||||||||||||||||
| 139 | 0 | $events{$year} = []; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | else | ||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | 0 | push @{$events{$year}}, $l; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 0 | return \%events; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 11 | 1; | |||||||||||||||||||||||||||