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