File Coverage

blib/lib/DataStructure/LinkedList/Cell.pm
Criterion Covered Total %
statement 18 32 56.2
branch 0 12 0.0
condition n/a
subroutine 6 8 75.0
pod 2 2 100.0
total 26 54 48.1


line stmt bran cond sub pod time code
1             package DataStructure::LinkedList::Cell;
2              
3 1     1   13 use 5.006;
  1         2  
  1         31  
4 1     1   4 use strict;
  1         1  
  1         25  
5 1     1   3 use warnings FATAL => 'all';
  1         1  
  1         27  
6 1     1   469 use parent qw/Class::Accessor/;
  1         241  
  1         5  
7             __PACKAGE__->mk_accessors(qw/next data/);
8 1     1   2085 use Scalar::Util qw/blessed looks_like_number/;
  1         2  
  1         85  
9 1     1   3 use Carp;
  1         2  
  1         216  
10              
11             =head1 NAME
12              
13             DataStructure::LinkedList::Cell - a Cell of the LinkedList.
14              
15             =head1 VERSION
16              
17             Version 0.03
18              
19             =cut
20              
21             our $VERSION = '0.03';
22              
23             =head1 SYNOPSIS
24              
25             You can see DataStructure::LinkedList module's SYNOPSIS as a example.
26              
27             =cut
28              
29             =head1 SUBROUTINES/METHODS
30              
31             =head2 new
32              
33             constructor. reguire one argument (not necessary) as data.
34              
35             =cut
36              
37             sub new {
38 0     0 1   my $class = shift;
39 0           my $next = undef;
40 0           my $data = shift;
41 0           bless { next => $next, data => $data }, $class;
42             }
43              
44             =head2 data
45              
46             accessor for data.
47             data method is readble and writable as below.
48             thid method is provided by Class::Accessor.
49              
50             $self->data; # read
51             $self->data('some data') # write
52              
53             =cut
54              
55             =head2 next
56              
57             accessor for next cell of the LinkedList.
58             next method is readble and writable as below.
59             thid method is provided by Class::Accessor.
60              
61             $self->next; # read
62             $self->next($next_cell) # write
63              
64             a user doesn't usually use this method directly.
65              
66             =cut
67              
68             =head2 compare_to
69              
70             This method compares to value of self and it by argument.
71             If self value is big, this method return 1 and if it isn't so return 0.
72             Each cell is lined in the sorted state at the value in DataStructure::LinkedList. it's used for the sorting.
73             You can use any data as value of cell.
74             If scalar data you use, this method compares like dictionary.
75             If object data you use, you have to make orignal class and implement compare_to method.
76              
77             =cut
78              
79             sub compare_to {
80 0     0 1   my $self = shift;
81 0           my $cell = shift;
82              
83             # some object case
84 0 0         if (blessed($self->data)) {
85             # you have to implement compare_to method in your obj
86 0 0         if (!$cell->can('compare_to')) {
87 0           croak "You have to implement compare_to method in your object(" . ref($cell) . ").\n";
88             }
89 0 0         return $cell->compare_to($self->data) > 0 ? 1 : 0;
90             }
91              
92 0 0         if (looks_like_number($self->data)) {
93             # number case
94 0 0         return $self->data > $cell->data ? 1 : 0;
95             } else {
96             # string case
97 0 0         return $self->data gt $cell->data ? 1 : 0;
98             }
99              
100             # other case (havn't implemented)
101 0           return 1;
102             }
103              
104             =head1 AUTHOR
105              
106             Shinchi Takahiro, C<< >>
107              
108             =head1 BUGS
109              
110             Please report any bugs or feature requests to C, or through
111             the web interface at L. I will be notified, and then you'll
112             automatically be notified of progress on your bug as I make changes.
113              
114              
115              
116              
117             =head1 SUPPORT
118              
119             You can find documentation for this module with the perldoc command.
120              
121             perldoc DataStructure::LinkedList::Cell
122              
123              
124             You can also look for information at:
125              
126             =over 4
127              
128             =item * RT: CPAN's request tracker (report bugs here)
129              
130             L
131              
132             =item * AnnoCPAN: Annotated CPAN documentation
133              
134             L
135              
136             =item * CPAN Ratings
137              
138             L
139              
140             =item * Search CPAN
141              
142             L
143              
144             =back
145              
146              
147             =head1 ACKNOWLEDGEMENTS
148              
149              
150             =head1 LICENSE AND COPYRIGHT
151              
152             Copyright 2014 Shinchi Takahiro.
153              
154             This program is free software; you can redistribute it and/or modify it
155             under the terms of the the Artistic License (2.0). You may obtain a
156             copy of the full license at:
157              
158             L
159              
160             Any use, modification, and distribution of the Standard or Modified
161             Versions is governed by this Artistic License. By using, modifying or
162             distributing the Package, you accept this license. Do not use, modify,
163             or distribute the Package, if you do not accept this license.
164              
165             If your Modified Version has been derived from a Modified Version made
166             by someone other than you, you are nevertheless required to ensure that
167             your Modified Version complies with the requirements of this license.
168              
169             This license does not grant you the right to use any trademark, service
170             mark, tradename, or logo of the Copyright Holder.
171              
172             This license includes the non-exclusive, worldwide, free-of-charge
173             patent license to make, have made, use, offer to sell, sell, import and
174             otherwise transfer the Package with respect to any patent claims
175             licensable by the Copyright Holder that are necessarily infringed by the
176             Package. If you institute patent litigation (including a cross-claim or
177             counterclaim) against any party alleging that the Package constitutes
178             direct or contributory patent infringement, then this Artistic License
179             to you shall terminate on the date that such litigation is filed.
180              
181             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
182             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
183             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
184             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
185             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
186             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
187             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
188             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
189              
190              
191             =cut
192              
193             1; # End of DataStructure::LinkedLis::Cell