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