| 1 | package Ordeal::Model::Backend::YAML; | ||||||||||
| 2 | |||||||||||
| 3 | # vim: ts=3 sts=3 sw=3 et ai : | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.020; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; # redundant, but still useful to document | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | { our $VERSION = '0.003'; } | |||||||||
| 9 | 2 | ▶ | use Mo qw< default builder >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Ouch; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use YAML::Tiny qw< LoadFile >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | use experimental qw< signatures postderef >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 2 | ▶ | no warnings qw< experimental::signatures experimental::postderef >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 2 | extends 'Ordeal::Model::Backend::PlainFile'; | |||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | use Ordeal::Model::Deck; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 2 | has _decks => (is => 'rw', lazy => 1, builder => '_build_decks'); | |||||||||
| 23 | |||||||||||
| 24 | ▶ | sub deck ($self, $id) { | |||||||||
|
Subroutine
deck: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 25 | 2 | ▶ | my $d = $self->_decks->{$id} or ouch 404, "not found: deck '$id'"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 1 | $_ = $self->card($_) for $d->{cards}->@*; # turn cards into Cards | |||||||||
| 27 | 1 | return Ordeal::Model::Deck->new( | |||||||||
| 28 | name => $id, # default value | ||||||||||
| 29 | group => '', # default value | ||||||||||
| 30 | $d->%*, # whatever was read | ||||||||||
| 31 | id => $id, # this overrides whatever is in $d->%* | ||||||||||
| 32 | ); | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub decks ($self) { keys $self->_decks->%* } | ||||||||
|
Subroutine
decks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 36 | |||||||||||
| 37 | ▶ | sub _build_decks ($s) { | |||||||||
|
Subroutine
_build_decks: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 1 | return LoadFile(path($s->base_directory, 'decks.yml')->stringify); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 2 | 1; | |||||||||
| 42 | __END__ | ||||||||||