| 1 | package NetHack::Logfile::Entry::32; | ||||||||||||||||||||
| 2 | 2 | our $VERSION = '1.00'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Moose::Util::TypeConstraints 'enum'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use NetHack::Logfile::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | extends 'NetHack::Logfile::Entry'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | field score => ( | |||||||||||||||||||
| 10 | isa => 'Int', | ||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | field dungeon => ( | |||||||||||||||||||
| 14 | isa => (enum [ | ||||||||||||||||||||
| 15 | "The Dungeons of Doom", | ||||||||||||||||||||
| 16 | "Gehennom", | ||||||||||||||||||||
| 17 | "The Gnomish Mines", | ||||||||||||||||||||
| 18 | "The Quest", | ||||||||||||||||||||
| 19 | "Sokoban", | ||||||||||||||||||||
| 20 | "Fort Ludios", | ||||||||||||||||||||
| 21 | "Vlad's Tower", | ||||||||||||||||||||
| 22 | "Endgame", | ||||||||||||||||||||
| 23 | ]), | ||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | field current_depth => ( | |||||||||||||||||||
| 27 | isa => 'Int', | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 2 | field deepest_depth => ( | |||||||||||||||||||
| 31 | isa => 'Int', | ||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 2 | field current_hp => ( | |||||||||||||||||||
| 35 | isa => 'Int', | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | field maximum_hp => ( | |||||||||||||||||||
| 39 | isa => 'Int', | ||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 2 | field deaths => ( | |||||||||||||||||||
| 43 | isa => 'Int', | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 2 | field 'birth_date'; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 2 | field 'death_date'; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2 | field uid => ( | |||||||||||||||||||
| 51 | isa => 'Int', | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 2 | field role => ( | |||||||||||||||||||
| 55 | isa => (enum [qw/archeologist barbarian caveman elf healer knight priest rogue samurai tourist valkyrie wizard/]), | ||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | field gender => ( | |||||||||||||||||||
| 59 | isa => (enum [qw/male female/]), | ||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 2 | field 'player'; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 2 | field 'death'; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 2 | my @fields = qw/version score dungeon current_depth deepest_depth current_hp | |||||||||||||||||||
| 67 | maximum_hp deaths death_date birth_date uid role gender player | ||||||||||||||||||||
| 68 | death/; | ||||||||||||||||||||
| 69 | 1 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 70 | 1 | my $self = shift; | |||||||||||||||||||
| 71 | 1 | my $input = shift; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | ▶ | return unless my @captures = $input =~ m{ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | ^ # start of line | ||||||||||||||||||||
| 75 | ([\d\.]+) [ ] # version | ||||||||||||||||||||
| 76 | ([\d\-]+) [ ] # score | ||||||||||||||||||||
| 77 | ([\d\-]+) [ ] # dungeon | ||||||||||||||||||||
| 78 | ([\d\-]+) [ ] # current_depth | ||||||||||||||||||||
| 79 | ([\d\-]+) [ ] # deepest_depth | ||||||||||||||||||||
| 80 | ([\d\-]+) [ ] # current_hp | ||||||||||||||||||||
| 81 | ([\d\-]+) [ ] # maximum_hp | ||||||||||||||||||||
| 82 | (\d+) [ ] # deaths | ||||||||||||||||||||
| 83 | (\d+) [ ] # death_date | ||||||||||||||||||||
| 84 | (\d+) [ ] # birth_date | ||||||||||||||||||||
| 85 | (\d+) [ ] # uid | ||||||||||||||||||||
| 86 | ([A-Z]) # role | ||||||||||||||||||||
| 87 | ([MF]) [ ] # gender | ||||||||||||||||||||
| 88 | ([^,]+) # player | ||||||||||||||||||||
| 89 | , # literal comma | ||||||||||||||||||||
| 90 | (.*) # death | ||||||||||||||||||||
| 91 | $ # end of line | ||||||||||||||||||||
| 92 | }x; | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 1 | my %parsed; | |||||||||||||||||||
| 95 | 1 | @parsed{@fields} = @captures; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 1 | return \%parsed; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 2 | my @dungeons = ( | |||||||||||||||||||
| 101 | "The Dungeons of Doom", | ||||||||||||||||||||
| 102 | "Gehennom", | ||||||||||||||||||||
| 103 | "The Gnomish Mines", | ||||||||||||||||||||
| 104 | "The Quest", | ||||||||||||||||||||
| 105 | "Sokoban", | ||||||||||||||||||||
| 106 | "Fort Ludios", | ||||||||||||||||||||
| 107 | "Vlad's Tower", | ||||||||||||||||||||
| 108 | "Endgame", | ||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||
| 110 | 2 | ▶ | sub canonicalize_dungeon { | ||||||||||||||||||
|
Subroutine
canonicalize_dungeon: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 111 | 2 | my $self = shift; | |||||||||||||||||||
| 112 | 2 | my $dnum = shift; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 2 | return $dungeons[$dnum]; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 2 | my %roles = ( | |||||||||||||||||||
| 118 | A => 'archeologist', | ||||||||||||||||||||
| 119 | B => 'barbarian', | ||||||||||||||||||||
| 120 | C => 'caveman', | ||||||||||||||||||||
| 121 | E => 'elf', | ||||||||||||||||||||
| 122 | H => 'healer', | ||||||||||||||||||||
| 123 | K => 'knight', | ||||||||||||||||||||
| 124 | P => 'priest', | ||||||||||||||||||||
| 125 | R => 'rogue', | ||||||||||||||||||||
| 126 | S => 'samurai', | ||||||||||||||||||||
| 127 | T => 'tourist', | ||||||||||||||||||||
| 128 | V => 'valkyrie', | ||||||||||||||||||||
| 129 | W => 'wizard', | ||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||
| 131 | 1 | ▶ | sub canonicalize_role { | ||||||||||||||||||
|
Subroutine
canonicalize_role: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 132 | 1 | my $self = shift; | |||||||||||||||||||
| 133 | 1 | my $letter = shift; | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 1 | return $roles{$letter}; | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 2 | my %genders = ( | |||||||||||||||||||
| 139 | M => 'male', | ||||||||||||||||||||
| 140 | F => 'female', | ||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||
| 142 | 1 | ▶ | sub canonicalize_gender { | ||||||||||||||||||
|
Subroutine
canonicalize_gender: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 143 | 1 | my $self = shift; | |||||||||||||||||||
| 144 | 1 | my $letter = shift; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 1 | return $genders{$letter}; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 2 | my @output_methods = qw/version score dungeon_number current_depth deepest_depth | |||||||||||||||||||
| 150 | current_hp maximum_hp deaths death_date birth_date uid | ||||||||||||||||||||
| 151 | role_one gender_one player death/; | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 1 | ▶ | sub as_line { | ||||||||||||||||||
|
Subroutine
as_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 154 | 1 | my $self = shift; | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | sprintf '%s %d %d %d %d %d %d %d %d %d %d %1.1s%1.1s %s,%s', | ||||||||||||||||||||
| 157 | 1 | map { $self->$_ } @output_methods; | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 2 | ▶ | sub ascended { shift->death eq 'ascended' } | ||||||||||||||||||
|
Subroutine
ascended: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 2 | my %dungeon_number = ( | |||||||||||||||||||
| 164 | "The Dungeons of Doom" => 0, | ||||||||||||||||||||
| 165 | "Gehennom" => 1, | ||||||||||||||||||||
| 166 | "The Gnomish Mines" => 2, | ||||||||||||||||||||
| 167 | "The Quest" => 3, | ||||||||||||||||||||
| 168 | "Sokoban" => 4, | ||||||||||||||||||||
| 169 | "Fort Ludios" => 5, | ||||||||||||||||||||
| 170 | "Vlad's Tower" => 6, | ||||||||||||||||||||
| 171 | "Endgame" => 7, | ||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||
| 173 | 4 | ▶ | sub dungeon_number { | ||||||||||||||||||
|
Subroutine
dungeon_number: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 174 | 4 | my $self = shift; | |||||||||||||||||||
| 175 | 4 | ▶ | my $dungeon = $self->dungeon || shift; | ||||||||||||||||||
|
Condition33%1/3
$self->dungeon || shift()
MC/DC0%0/2
$self->dungeon || shift()
$self->dungeon
shift()
Truth table33%1/3
A || B
A= $self->dungeonB= shift()
| |||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | 4 | return $dungeon_number{$dungeon}; | |||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 2 | ▶ | sub abbreviate_cg { | ||||||||||||||||||
|
Subroutine
abbreviate_cg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 181 | 2 | my $self = shift; | |||||||||||||||||||
| 182 | 2 | my $method = shift; | |||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 2 | return ucfirst substr($self->$method, 0, 1); | |||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | 1 | ▶ | sub role_one { shift->abbreviate_cg('role') } | ||||||||||||||||||
|
Subroutine
role_one: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 187 | 1 | ▶ | sub gender_one { shift->abbreviate_cg('gender') } | ||||||||||||||||||
|
Subroutine
gender_one: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 190 | 2 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 191 | 2 | ▶ | no Moose::Util::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 2 | 1; | |||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||