The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Ordeal::Model::Backend::YAML - Cards/deck definition via YAML file

SYNOPSIS

   use Ordeal::Model;
   use Ordeal::Model::Backend::YAML;

   # definition in "decks.yml", cards in "cards/*" inside base_directory
   my $backend = Ordeal::Model::Backend::YAML->new(
      base_directory => '/path/to/base'
   );
   my $model = Ordeal::Model->new(backend => $backend);

   # get identifiers of all decks
   my @decks = $backend->decks; # OR
      @decks = $model->get_deck_ids;

   my $deck = $backend->deck($deck_id); # OR
      $deck = $model->get_deck($deck_id);

   my $card = $backend->card($card_id); # OR
      $card = $model->get_card($card_id);

   my $card_path = $backend->path_for(card => $card_id);

   my $ct = $backend->content_type_for('jpg');

DESCRIPTION

This module is a simple file-based backend for Ordeal::Model; cards are assumed to be files, while the definition of all decks is inside a YAML file.

It is based on a directory with the following structure:

   *
   +- cards *
   |        +- card1.jpg
   |        +- card2.jpg
   |        ...
   |
   +- decks.yml

Cards are PNG, JPG or SVG files.

Decks are defined inside file decks.yml, in YAML format, composed of an associative array whose keys are deck identifiers and the associated values are associative arrays themselves, each defining a deck with the following keys:

cards

(mandatory) list of card identifiers, i.e. file names referred to the cards sub-directory.

description

(optional) description of the deck.

Example of a decks.yml file:

   deck1:
      description: foo
      cards:
         - card1.jpg
         - card2.jpg
   deck2:
      cards:
         - card3.jpg
         - card1.jpg
         - card4.jpg

METHODS

This class inherits from Ordeal::Model::Backend::PlainFile so it has its methods.

BUGS AND LIMITATIONS

The code leverages some experimental Perl features like signatures and postderef; for this reason, at least perl 5.20 will be needed.

Report bugs through GitHub (patches welcome) at https://github.com/polettix/Ordeal-Model.

AUTHOR

Flavio Poletti <polettix@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2018 by Flavio Poletti <polettix@cpan.org>

This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.