| 1 | # | ||
| 2 | # This file is part of WWW-DaysOfWonder-Memoir44 | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2009 by Jerome Quelin. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | 3 | ▶ | use 5.012; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | package WWW::DaysOfWonder::Memoir44::DB::Scenarios; | ||
| 14 | # ABSTRACT: scenarios database | ||
| 15 | 3 | $WWW::DaysOfWonder::Memoir44::DB::Scenarios::VERSION = '3.000'; | |
| 16 | 3 | ▶ | use DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 3 | ▶ | use MooseX::Singleton; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 3 | ▶ | use MooseX::Has::Sugar; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 3 | ▶ | use Path::Class; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 3 | ▶ | use Storable qw{ nstore retrieve }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | 3 | ▶ | use WWW::DaysOfWonder::Memoir44::DB::Params; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 3 | ▶ | use WWW::DaysOfWonder::Memoir44::Utils qw{ $DATADIR }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | |||
| 25 | |||
| 26 | 3 | my $dbfile = $DATADIR->file( "scenarios.store" ); | |
| 27 | |||
| 28 | has scenarios => ( | ||
| 29 | rw, auto_deref, | ||
| 30 | traits => ['Array'], | ||
| 31 | isa => 'ArrayRef[WWW::DaysOfWonder::Memoir44::Scenario]', | ||
| 32 | 0 | ▶ | default => sub { [] }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 33 | 3 | writer => '_set_scenarios', | |
| 34 | handles => { | ||
| 35 | nb_scenarios => 'count', # my $nb = $db->nb_scenarios; | ||
| 36 | add => 'push', # $db->add( $scenario, $scenario ); | ||
| 37 | clear => 'clear', # $db->clear; | ||
| 38 | grep => 'grep', # $db->grep( sub { $_->need_ef }); | ||
| 39 | } | ||
| 40 | ); | ||
| 41 | |||
| 42 | |||
| 43 | # -- public methods | ||
| 44 | |||
| 45 | |||
| 46 | # implemented by the 'Array' trait of the 'scenarios' attribute. | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | # implemented by the 'Array' trait of the 'scenarios' attribute. | ||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | 0 | ▶ | sub read { |
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 55 | 0 | my $self = shift; | |
| 56 | |||
| 57 | 0 | my $scenarios_ref = retrieve( $dbfile->stringify ); | |
| 58 | 0 | $self->_set_scenarios( $scenarios_ref ); | |
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | |||
| 63 | 0 | ▶ | sub write { |
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 64 | 0 | my $self = shift; | |
| 65 | 0 | my @scenarios = $self->scenarios; | |
| 66 | 0 | nstore( \@scenarios, $dbfile->stringify ); | |
| 67 | |||
| 68 | # store timestamp | ||
| 69 | 0 | my $params = WWW::DaysOfWonder::Memoir44::DB::Params->instance; | |
| 70 | 0 | my $today = DateTime->today->ymd; | |
| 71 | 0 | $params->set( last_updated => $today ); | |
| 72 | } | ||
| 73 | |||
| 74 | 3 | 1; | |
| 75 | |||
| 76 | __END__ | ||