NAME
Ordeal::Model::Backend::PlainFile - Cards/decks management via plain files
SYNOPSIS
use
Ordeal::Model;
my
$backend
= Ordeal::Model::Backend::PlainFile->new(
base_directory
=>
'/path/to/base'
);
my
$model
= Ordeal::Model->new(
backend
=>
$backend
);
my
$card
=
$backend
->card(
$card_id
);
# OR
$card
=
$model
->get_card(
$card_id
);
my
$deck
=
$backend
->deck(
$deck_id
);
# OR
$deck
=
$model
->get_deck(
$deck_id
);
my
$card_path
=
$backend
->path_for(
card
=>
$card_id
);
my
$deck_path
=
$backend
->path_for(
deck
=>
$deck_id
);
my
$ct
=
$backend
->content_type_for(
'jpg'
);
DESCRIPTION
This module is a simple file-based backend for Ordeal::Model.
It is based on a directory with the following structure:
*
+- cards *
| +- card1.jpg
| +- card2.jpg
| ...
|
+- decks *
+- deck1
+- deck2
...
Cards are PNG
, JPG
or SVG
files.
Decks are either directories with cards inside (or links to cards), or plain text files with the lists.
METHODS
base_directory
my
$dir
=
$obj
->base_directory;
$obj
->base_directory(
'/path/to/somewhere'
);
accessor for the base directory where cards and decks are kept.
card
my
$card
=
$obj
->card(
$id
);
get a card by identifier. Returns a Ordeal::Model::Card object.
content_type_for
my
$ct
=
$obj
->content_type_for(
$extension
);
get the Content-Type for the specific extension, supported ones are PNG
, JPG
or SVG
, case-insensitive.
deck
my
$deck
=
$obj
->deck(
$id
);
get a deck by identifier. The order of the cards in the deck is either lexicographic (for directory-based decks) or the order they are found in the plain text file.
decks
my
$decks
=
$obj
->decks;
Get a list of all available decks.
path_for
my
$deck_path
=
$obj
->path_for(
decks
=>
$deck_id
);
my
$card_path
=
$obj
->path_for(
cards
=>
$card_id
);
get path to the specific object, based on "base_directory".
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.