File Coverage

blib/lib/HTML/Widgets/NavMenu/ToJSON/Data_Persistence/YAML.pm
Criterion Covered Total %
statement 28 29 96.5
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 39 41 95.1


line stmt bran cond sub pod time code
1             package HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML;
2              
3 2     2   1099 use 5.008;
  2         5  
  2         63  
4 2     2   14 use strict;
  2         4  
  2         54  
5 2     2   13 use warnings FATAL => 'all';
  2         2  
  2         63  
6              
7 2     2   8 use parent 'HTML::Widgets::NavMenu::ToJSON::Data_Persistence';
  2         3  
  2         8  
8              
9 2     2   911 use YAML::XS ();
  2         4009  
  2         341  
10              
11             =head1 NAME
12              
13             HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML - YAML-based persistence
14             for L .
15              
16             =head1 VERSION
17              
18             Version 0.0.6
19              
20             =cut
21              
22             our $VERSION = '0.0.6';
23              
24             __PACKAGE__->mk_acc_ref([ qw( _filename ) ]);
25              
26             sub _init
27             {
28 1     1   612 my ($self, $args) = @_;
29              
30 1         11 $self->_filename($args->{filename});
31              
32 1         2 return;
33             }
34              
35             =head1 SYNOPSIS
36              
37             See HTML::Widgets::NavMenu::ToJSON .
38              
39             =head1 DESCRIPTION
40              
41             This is a sub-class of L
42             for providing coarse-grained persistence using a serialised YAML store as
43             storage.
44              
45             =head1 SUBROUTINES/METHODS
46              
47             =head2 HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML->new({ filename => '/path/to/filename.yml' });
48              
49             Initializes the persistence store with the YAML file in $args->{filename} .
50              
51             =cut
52              
53             =head2 $self->load()
54              
55             Loads the data from the file.
56              
57             =cut
58              
59             sub load
60             {
61 1     1 1 2 my $self = shift;
62              
63 1         1 my $data;
64              
65 1 50       2 if (!eval
66             {
67 1         7 ($data) = YAML::XS::LoadFile($self->_filename());
68              
69 0         0 1;
70             })
71             {
72 1         62 $data = $self->_calc_initial_data();
73             }
74              
75             $self->_data(
76 1         6 $data
77             );
78              
79 1         2 return;
80             }
81              
82             =head2 $self->save()
83              
84             Saves the data from the file.
85              
86             =cut
87              
88             sub save
89             {
90 1     1 1 2 my $self = shift;
91              
92 1         6 YAML::XS::DumpFile(
93             $self->_filename,
94             $self->_data
95             );
96              
97 1         242 return;
98             }
99              
100             =head1 AUTHOR
101              
102             Shlomi Fish, C<< >>
103              
104             =head1 BUGS
105              
106             Please report any bugs or feature requests to C, or through
107             the web interface at L. I will be notified, and then you'll
108             automatically be notified of progress on your bug as I make changes.
109              
110              
111              
112              
113             =head1 SUPPORT
114              
115             You can find documentation for this module with the perldoc command.
116              
117             perldoc HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML
118              
119              
120             You can also look for information at:
121              
122             =over 4
123              
124             =item * RT: CPAN's request tracker (report bugs here)
125              
126             L
127              
128             =item * AnnoCPAN: Annotated CPAN documentation
129              
130             L
131              
132             =item * CPAN Ratings
133              
134             L
135              
136             =item * Search CPAN
137              
138             L
139              
140             =back
141              
142              
143             =head1 ACKNOWLEDGEMENTS
144              
145              
146             =head1 LICENSE AND COPYRIGHT
147              
148             Copyright 2012 Shlomi Fish.
149              
150             This program is free software; you can redistribute it and/or modify it
151             under the terms of the the Artistic License (2.0). You may obtain a
152             copy of the full license at:
153              
154             L
155              
156             Any use, modification, and distribution of the Standard or Modified
157             Versions is governed by this Artistic License. By using, modifying or
158             distributing the Package, you accept this license. Do not use, modify,
159             or distribute the Package, if you do not accept this license.
160              
161             If your Modified Version has been derived from a Modified Version made
162             by someone other than you, you are nevertheless required to ensure that
163             your Modified Version complies with the requirements of this license.
164              
165             This license does not grant you the right to use any trademark, service
166             mark, tradename, or logo of the Copyright Holder.
167              
168             This license includes the non-exclusive, worldwide, free-of-charge
169             patent license to make, have made, use, offer to sell, sell, import and
170             otherwise transfer the Package with respect to any patent claims
171             licensable by the Copyright Holder that are necessarily infringed by the
172             Package. If you institute patent litigation (including a cross-claim or
173             counterclaim) against any party alleging that the Package constitutes
174             direct or contributory patent infringement, then this Artistic License
175             to you shall terminate on the date that such litigation is filed.
176              
177             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
178             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
179             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
180             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
181             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
182             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
183             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
184             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
185              
186              
187             =cut
188              
189             1; # End of HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML