File Coverage

blib/lib/HTML/Widgets/NavMenu/ToJSON/Data_Persistence.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 30 31 96.7


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