blib/lib/HTML/Widgets/NavMenu/ToJSON/Data_Persistence/YAML.pm

filter: Statementstmt 96.7% 30 / 31 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 95.3% 41 / 43 CC 2 SCAR 2.1
CC
2
Cov
94%
load
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/HTML/Widgets/NavMenu/ToJSON/Data_Persistence.pm ↑ Summary
1 package HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML;
2  
3 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use parent 'HTML::Widgets::NavMenu::ToJSON::Data_Persistence';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML - YAML-based persistence
14 for L<HTML::Widgets::NavMenu::ToJSON> .
15  
16 =head1 VERSION
17  
18 Version 0.0.3
19  
20 =cut
21  
22 3 our $VERSION = '0.0.3';
23  
24 3 __PACKAGE__->mk_acc_ref([ qw( _filename ) ]);
25  
26 sub _init
27 {
28 1 ▶ my ($self, $args) = @_;
Subroutine _init: called CC=1 SCAR=0.0
29  
30 1 $self->_filename($args->{filename});
31  
32 1 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<HTML::Widgets::NavMenu::ToJSON::Data_Persistence>
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 ▶ my $self = shift;
Subroutine load: called CC=2 SCAR=7.1
Pod documented
62  
63 1 my $data;
64  
65 1 ▶ if (!eval
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { ($data) = YAML::XS::LoadFile($self->_filename); 1 } }) 1 0 1
66 {
67 1 ($data) = YAML::XS::LoadFile($self->_filename());
68  
69 0 1;
70 })
71 {
72 1 $data = $self->_calc_initial_data();
73 }
74  
75 $self->_data(
76 1 $data
77 );
78  
79 1 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 ▶ my $self = shift;
Subroutine save: called CC=1 SCAR=0.0
Pod documented
91  
92 1 YAML::XS::DumpFile(
93 $self->_filename,
94 $self->_data
95 );
96  
97 1 return;
98 }
99  
100 =head1 AUTHOR
101  
102 Shlomi Fish, C<< <shlomif at cpan.org> >>
103  
104 =head1 BUGS
105  
106 Please report any bugs or feature requests to C<bug-html-widgets-navmenu-tojson at rt.cpan.org>, or through
107 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Widgets-NavMenu-ToJSON>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Widgets-NavMenu-ToJSON>
127  
128 =item * AnnoCPAN: Annotated CPAN documentation
129  
130 L<http://annocpan.org/dist/HTML-Widgets-NavMenu-ToJSON>
131  
132 =item * CPAN Ratings
133  
134 L<http://cpanratings.perl.org/d/HTML-Widgets-NavMenu-ToJSON>
135  
136 =item * Search CPAN
137  
138 L<http://search.cpan.org/dist/HTML-Widgets-NavMenu-ToJSON/>
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<http://www.perlfoundation.org/artistic_license_2_0>
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 3 1; # End of HTML::Widgets::NavMenu::ToJSON::Data_Persistence::YAML
« blib/lib/HTML/Widgets/NavMenu/ToJSON/Data_Persistence.pm ↑ Summary