| 1 | package NetHack::Logfile::Entry::33; | ||||||||||
| 2 | 1 | our $VERSION = '1.00'; | |||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Moose::Util::TypeConstraints 'enum'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use NetHack::Logfile::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | extends 'NetHack::Logfile::Entry::32'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | field '+role' => ( | |||||||||
| 10 | isa => (enum [qw/archeologist barbarian caveman healer knight monk priest ranger rogue samurai tourist valkyrie wizard/]), | ||||||||||
| 11 | ); | ||||||||||
| 12 | |||||||||||
| 13 | 1 | field race => ( | |||||||||
| 14 | isa => (enum [qw/human elf dwarf gnome orc/]), | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 1 | field alignment => ( | |||||||||
| 18 | isa => (enum [qw/lawful neutral chaotic/]), | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 1 | my @fields = qw/version score dungeon current_depth deepest_depth current_hp | |||||||||
| 22 | maximum_hp deaths death_date birth_date uid role race gender | ||||||||||
| 23 | alignment player death/; | ||||||||||
| 24 | 1 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 25 | 1 | my $self = shift; | |||||||||
| 26 | 1 | my $input = shift; | |||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | return unless my @captures = $input =~ m{ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | ^ # start of line | ||||||||||
| 30 | ([\d\.]+) [ ] # version | ||||||||||
| 31 | ([\d\-]+) [ ] # score | ||||||||||
| 32 | ([\d\-]+) [ ] # dungeon | ||||||||||
| 33 | ([\d\-]+) [ ] # current_depth | ||||||||||
| 34 | ([\d\-]+) [ ] # deepest_depth | ||||||||||
| 35 | ([\d\-]+) [ ] # current_hp | ||||||||||
| 36 | ([\d\-]+) [ ] # maximum_hp | ||||||||||
| 37 | (\d+) [ ] # deaths | ||||||||||
| 38 | (\d+) [ ] # death_date | ||||||||||
| 39 | (\d+) [ ] # birth_date | ||||||||||
| 40 | (\d+) [ ] # uid | ||||||||||
| 41 | ([A-Z][a-z][a-z]) [ ] # role | ||||||||||
| 42 | ([A-Z][a-z][a-z]) [ ] # race | ||||||||||
| 43 | ([MF][ae][lm]) [ ] # gender | ||||||||||
| 44 | ([A-Z][a-z][a-z]) [ ] # alignment | ||||||||||
| 45 | ([^,]+) # player | ||||||||||
| 46 | , # literal comma | ||||||||||
| 47 | (.*) # death | ||||||||||
| 48 | $ # end of line | ||||||||||
| 49 | }x; | ||||||||||
| 50 | |||||||||||
| 51 | 1 | my %parsed; | |||||||||
| 52 | 1 | @parsed{@fields} = @captures; | |||||||||
| 53 | |||||||||||
| 54 | 1 | return \%parsed; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | my %roles = ( | |||||||||
| 58 | Arc => 'archeologist', | ||||||||||
| 59 | Bar => 'barbarian', | ||||||||||
| 60 | Cav => 'caveman', | ||||||||||
| 61 | Hea => 'healer', | ||||||||||
| 62 | Kni => 'knight', | ||||||||||
| 63 | Mon => 'monk', | ||||||||||
| 64 | Pri => 'priest', | ||||||||||
| 65 | Ran => 'ranger', | ||||||||||
| 66 | Rog => 'rogue', | ||||||||||
| 67 | Sam => 'samurai', | ||||||||||
| 68 | Tou => 'tourist', | ||||||||||
| 69 | Val => 'valkyrie', | ||||||||||
| 70 | Wiz => 'wizard', | ||||||||||
| 71 | ); | ||||||||||
| 72 | 1 | ▶ | sub canonicalize_role { | ||||||||
|
Subroutine
canonicalize_role: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 73 | 1 | my $self = shift; | |||||||||
| 74 | 1 | my $letter = shift; | |||||||||
| 75 | |||||||||||
| 76 | 1 | return $roles{$letter}; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 1 | my %genders = ( | |||||||||
| 80 | Mal => 'male', | ||||||||||
| 81 | Fem => 'female', | ||||||||||
| 82 | ); | ||||||||||
| 83 | 1 | ▶ | sub canonicalize_gender { | ||||||||
|
Subroutine
canonicalize_gender: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 1 | my $self = shift; | |||||||||
| 85 | 1 | my $abbrev = shift; | |||||||||
| 86 | |||||||||||
| 87 | 1 | return $genders{$abbrev}; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | my %races = ( | |||||||||
| 91 | Hum => 'human', | ||||||||||
| 92 | Elf => 'elf', | ||||||||||
| 93 | Dwa => 'dwarf', | ||||||||||
| 94 | Gno => 'gnome', | ||||||||||
| 95 | Orc => 'orc', | ||||||||||
| 96 | ); | ||||||||||
| 97 | 1 | ▶ | sub canonicalize_race { | ||||||||
|
Subroutine
canonicalize_race: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 98 | 1 | my $self = shift; | |||||||||
| 99 | 1 | my $abbrev = shift; | |||||||||
| 100 | |||||||||||
| 101 | 1 | return $races{$abbrev}; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 1 | my %alignments = ( | |||||||||
| 105 | Law => 'lawful', | ||||||||||
| 106 | Neu => 'neutral', | ||||||||||
| 107 | Cha => 'chaotic', | ||||||||||
| 108 | ); | ||||||||||
| 109 | 1 | ▶ | sub canonicalize_alignment { | ||||||||
|
Subroutine
canonicalize_alignment: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 110 | 1 | my $self = shift; | |||||||||
| 111 | 1 | my $abbrev = shift; | |||||||||
| 112 | |||||||||||
| 113 | 1 | return $alignments{$abbrev}; | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 1 | my @output_methods = qw/version score dungeon_number current_depth | |||||||||
| 117 | deepest_depth current_hp maximum_hp deaths death_date | ||||||||||
| 118 | birth_date uid role_three race_three gender_three | ||||||||||
| 119 | alignment_three player death/; | ||||||||||
| 120 | |||||||||||
| 121 | 1 | ▶ | sub as_line { | ||||||||
|
Subroutine
as_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 122 | 1 | my $self = shift; | |||||||||
| 123 | |||||||||||
| 124 | sprintf '%s %d %d %d %d %d %d %d %d %d %d %s %s %s %s %s,%s', | ||||||||||
| 125 | 1 | map { $self->$_ } @output_methods; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 4 | ▶ | sub abbreviate_crga { | ||||||||
|
Subroutine
abbreviate_crga: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 129 | 4 | my $self = shift; | |||||||||
| 130 | 4 | my $method = shift; | |||||||||
| 131 | |||||||||||
| 132 | 4 | return ucfirst lc substr($self->$method, 0, 3); | |||||||||
| 133 | } | ||||||||||
| 134 | 1 | ▶ | sub role_three { shift->abbreviate_crga('role') } | ||||||||
|
Subroutine
role_three: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 135 | 1 | ▶ | sub race_three { shift->abbreviate_crga('race') } | ||||||||
|
Subroutine
race_three: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 136 | 1 | ▶ | sub gender_three { shift->abbreviate_crga('gender') } | ||||||||
|
Subroutine
gender_three: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 137 | 1 | ▶ | sub alignment_three { shift->abbreviate_crga('alignment') } | ||||||||
|
Subroutine
alignment_three: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 138 | |||||||||||
| 139 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 140 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 141 | 1 | ▶ | no Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 142 | |||||||||||
| 143 | 1 | 1; | |||||||||
| 144 | |||||||||||
| 145 | __END__ | ||||||||||