Data-Paginator-0.08000755000765000024 012425055123 13622 5ustar00gphatstaff000000000000README100644000765000024 55012425055123 14543 0ustar00gphatstaff000000000000Data-Paginator-0.08 This archive contains the distribution Data-Paginator, version 0.08: Pagination with Moose This software is copyright (c) 2014 by Cory G Watson. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.012. Changes100644000765000024 120612425055123 15175 0ustar00gphatstaff000000000000Data-Paginator-0.08Revision history for Data-Paginator 0.08 Oct 31 2014 0.07 Oct 27 2014 0.06 Oct 27 2014 0.05 Nov 22 2011 * Convert to Dist::Zilla * Fix bug that threw exceptions on empty pagination. 0.05 * Fix POD typo 0.04 * Document pages_per_set attribute. 0.03 * Fix problem that prevented subclassing Data::Paginator * Prevent division by zero when calling set_for with no pages_per_set set 0.02 November 25th, 2009 * Make current_page more lenient, adjusting invalid values to valid ones. * Add lots of methods * Add Pageset functionality 0.01 November 25th, 2009 First version, released on an unsuspecting world. LICENSE100644000765000024 4365612425055123 14746 0ustar00gphatstaff000000000000Data-Paginator-0.08This software is copyright (c) 2014 by Cory G Watson. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014 by Cory G Watson. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 by Cory G Watson. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End META.yml100644000765000024 122512425055123 15154 0ustar00gphatstaff000000000000Data-Paginator-0.08--- abstract: 'Pagination with Moose' author: - 'Cory G Watson ' build_requires: Test::More: 0 strict: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.012, CPAN::Meta::Converter version 2.133380' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Data-Paginator requires: Moose: 0 MooseX::Types: 0 MooseX::Types::Moose: 0 resources: bugtracker: https://github.com/gphat/data-paginator/issues homepage: https://github.com/gphat/data-paginator repository: https://github.com/gphat/data-paginator.git version: 0.08 MANIFEST100644000765000024 51412425055123 15014 0ustar00gphatstaff000000000000Data-Paginator-0.08# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.012. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README README.mkdn ignore.txt lib/Data/Paginator.pm lib/Data/Paginator/Types.pm t/00-load.t t/01-basic.t t/currpage.t t/empty.t t/pageset.t t/release-pod-syntax.t t/release-synopsis.t t/simple.t t000755000765000024 012425055123 14006 5ustar00gphatstaff000000000000Data-Paginator-0.08empty.t100644000765000024 35612425055123 15455 0ustar00gphatstaff000000000000Data-Paginator-0.08/t#!/usr/bin/perl use strict; use Test::More; use_ok('Data::Paginator'); my $pager = Data::Paginator->new( current_page => 0, entries_per_page => 10, total_entries => 0 ); cmp_ok($pager->current_page, '==', 1); done_testing;META.json100644000765000024 246612425055123 15334 0ustar00gphatstaff000000000000Data-Paginator-0.08{ "abstract" : "Pagination with Moose", "author" : [ "Cory G Watson " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.012, CPAN::Meta::Converter version 2.133380", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Data-Paginator", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Moose" : "0", "MooseX::Types" : "0", "MooseX::Types::Moose" : "0" } }, "test" : { "requires" : { "Test::More" : "0", "strict" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/gphat/data-paginator/issues" }, "homepage" : "https://github.com/gphat/data-paginator", "repository" : { "type" : "git", "url" : "https://github.com/gphat/data-paginator.git", "web" : "https://github.com/gphat/data-paginator" } }, "version" : "0.08" } ignore.txt100644000765000024 14512425055123 15707 0ustar00gphatstaff000000000000Data-Paginator-0.08blib* Makefile Makefile.old Build _build* pm_to_blib* *.tar.gz .lwpcookies Data-Paginator-* cover_db simple.t100644000765000024 761112425055123 15631 0ustar00gphatstaff000000000000Data-Paginator-0.08/t#!/usr/bin/perl -wT use strict; use Test::More; use_ok('Data::Paginator'); my $name; foreach my $line () { chomp $line; next unless $line; if ($line =~ /^# ?(.+)/) { $name = $1; next; } my @vals = map { /^undef$/ ? undef : /^''$/ ? '' : $_ } split /\s+/, $line; my $page = Data::Paginator->new( total_entries => $vals[0], entries_per_page => $vals[1], current_page => $vals[2] ); # print "New style\n"; check($page, $name, @vals); } my $page = Data::Paginator->new(total_entries => 0, entries_per_page => 10); isa_ok($page, 'Data::Paginator'); my @empty; my @spliced = $page->splice(\@empty); is(scalar(@spliced), 0, "Splice on empty is empty"); sub check { my ($page, $name, @vals) = @_; isa_ok($page, 'Data::Paginator'); is($page->first_page, $vals[3], "$name: first page"); is($page->last_page, $vals[4], "$name: last page"); is($page->first, $vals[5], "$name: first"); is($page->last, $vals[6], "$name: last"); is($page->previous_page, $vals[7], "$name: previous_page"); is($page->current_page, $vals[8], "$name: current_page"); is($page->next_page, $vals[9], "$name: next_page"); my @integers = (0 .. $vals[0] - 1); @integers = $page->splice(\@integers); my $integers = join ',', @integers; is($integers, $vals[10], "$name: splice"); is($page->entries_on_this_page, $vals[11], "$name: entries_on_this_page"); my $skipped = $vals[5] - 1; $skipped = 0 if $skipped < 0; is($page->skipped, $skipped, "$name: skipped"); } # Format of test data: 0=number of entries, 1=entries per page, 2=current page, # 3=first page, 4=last page, 5=first entry on page, 6=last entry on page, # 7=previous page, 8=current page, 9=next page, 10=current entries, 11=current number of entries done_testing; __DATA__ # Initial test 50 10 1 1 5 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 50 10 2 1 5 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 10 50 10 3 1 5 21 30 2 3 4 20,21,22,23,24,25,26,27,28,29 10 50 10 4 1 5 31 40 3 4 5 30,31,32,33,34,35,36,37,38,39 10 50 10 5 1 5 41 50 4 5 undef 40,41,42,43,44,45,46,47,48,49 10 # Under 10 1 10 1 1 1 1 1 undef 1 undef 0 1 2 10 1 1 1 1 2 undef 1 undef 0,1 2 3 10 1 1 1 1 3 undef 1 undef 0,1,2 3 4 10 1 1 1 1 4 undef 1 undef 0,1,2,3 4 5 10 1 1 1 1 5 undef 1 undef 0,1,2,3,4 5 6 10 1 1 1 1 6 undef 1 undef 0,1,2,3,4,5 6 7 10 1 1 1 1 7 undef 1 undef 0,1,2,3,4,5,6 7 8 10 1 1 1 1 8 undef 1 undef 0,1,2,3,4,5,6,7 8 9 10 1 1 1 1 9 undef 1 undef 0,1,2,3,4,5,6,7,8 9 10 10 1 1 1 1 10 undef 1 undef 0,1,2,3,4,5,6,7,8,9 10 # Over 10 11 10 1 1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 11 10 2 1 2 11 11 1 2 undef 10 1 12 10 1 1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 12 10 2 1 2 11 12 1 2 undef 10,11 2 13 10 1 1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 13 10 2 1 2 11 13 1 2 undef 10,11,12 3 # Under 20 19 10 1 1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 19 10 2 1 2 11 19 1 2 undef 10,11,12,13,14,15,16,17,18 9 20 10 1 1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 20 10 2 1 2 11 20 1 2 undef 10,11,12,13,14,15,16,17,18,19 10 # Over 20 21 10 1 1 3 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 21 10 2 1 3 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 10 21 10 3 1 3 21 21 2 3 undef 20 1 22 10 1 1 3 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 22 10 2 1 3 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 10 22 10 3 1 3 21 22 2 3 undef 20,21 2 23 10 1 1 3 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 10 23 10 2 1 3 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 10 23 10 3 1 3 21 23 2 3 undef 20,21,22 3 # Zero test 0 10 1 1 1 0 0 undef 1 undef '' 0README.mkdn100644000765000024 713512425055123 15521 0ustar00gphatstaff000000000000Data-Paginator-0.08# NAME Data::Paginator - Pagination with Moose # VERSION version 0.08 # SYNOPSIS use Data::Paginator; my $pager = Data::Paginator->new( current_page => 1, entries_per_page => 10, total_entries => 100, ); print "First page: ".$pager->first_page."\n"; print "Last page: ".$pager->last_page."\n"; print "First entry on page: ".$pager->first."\n"; print "Last entry on page: ".$pager->last."\n"; # DESCRIPTION This is yet another pagination module. It only exists because none of the other pager modules are written using Moose. Sometimes there is a Moose feature – MooseX::Storage, in my case – that you need. It's a pain when you can't use it with an existing module. This module aims to be completely compatible with the venerable [Data::Page](https://metacpan.org/pod/Data::Page). In fact, it's a pretty blatant copy of Data::Page, lifting code from some of it's methods. # SETS This module provides behavior compatible with [Data::PageSet](https://metacpan.org/pod/Data::PageSet), allowing you to break your pagination into sets. For example, if you have a large number of pages to show and would like to allow the user to 'jump' X pages at a time, you can set the `pages_per_set` attribute to X and populate the links in your pagination control with the values from `previous_set` and `next_set`. # ATTRIBUTES ## current\_page The current page. Defaults to 1. If you set this value to to a page number lesser than or greater than the range of the pager, then 1 or the last\_page will be returned instead. It is safe to pass this numbers like -1000 or 1000 when there are only 3 pages. ## entries\_per\_page The number of entries per page, required at instantiation. ## last\_page Returns the number of the last page. Lazily computed, so do not set. ## next\_set Returns the number of the next set or undefined if there is no next. ## pages\_per\_set If you have a large number of pages to show and would like to allow the user to 'jump' X pages at a time, you can set the `pages_per_set` attribute to X and populate the links in your pagination control with the values from `previous_set` and `next_set`. ## previous\_set Returns the set number of the previous set or undefined if there is no previous set. ## total\_entries The total number of entries this pager is covering. Required at instantiation. ## first Returns the number of the first entry on the current page. ## first\_page Always returns 1. # METHODS ## entries\_on\_this\_page Returns the number of entries on this page. ## first\_set Returns 1 if this Paginator has pages\_per\_set. Otherwise returns undef. ## last Returns the number of the last entry on the current page. ## next\_page Returns the page number of the next page if one exists, otherwise returns false. ## page\_for ($count) Returns the page number that the $count item appears on. Returns undef if $count is outside the bounds of this Paginator. ## previous\_page Returns the page number of the previous page if one exists, otherwise returns undef. ## set\_for $page Returns the set number of the specified page. Returns undef if the page exceeds the bounds of the Paginator. ## splice Takes in an arrayref and returns only the values which are on the current page. # ACKNOWLEDGEMENTS Léon Brocard and his work on [Data::Page](https://metacpan.org/pod/Data::Page). # AUTHOR Cory G Watson # COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Cory G Watson. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 00-load.t100644000765000024 23612425055124 15451 0ustar00gphatstaff000000000000Data-Paginator-0.08/t#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'Data::Paginator' ); } diag( "Testing Data::Paginator $Data::Paginator::VERSION, Perl $], $^X" ); pageset.t100644000765000024 274212425055124 15771 0ustar00gphatstaff000000000000Data-Paginator-0.08/t#!/usr/bin/perl -w use strict; use Test::More; use Data::Paginator; { my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => 1, pages_per_set => 2 # 3 sets }); cmp_ok($pager->current_set, '==', 1, 'current set is 1'); cmp_ok($pager->set_for(1), '==', 1, 'page 1 is in 1st set'); cmp_ok($pager->set_for(3), '==', 2, 'page 3 is in 2nd set'); cmp_ok($pager->next_set, '==', 9, 'next set page is 9'); ok(!defined($pager->previous_set), 'previous set is undefined'); } { my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => 3, pages_per_set => 2 # 3 sets }); cmp_ok($pager->current_set, '==', 2, 'current set is 2'); cmp_ok($pager->next_set, '==', 17, 'next set page is 9'); cmp_ok($pager->previous_set, '==', 1, 'previous set page is 1'); } { my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => 5, pages_per_set => 2 # 3 sets }); cmp_ok($pager->current_set, '==', 3, 'current set is 3'); ok(!defined($pager->next_set), 'next set page is undefined'); cmp_ok($pager->previous_set, '==', 9, 'next set page is 9'); } done_testing;Makefile.PL100644000765000024 224012425055124 15654 0ustar00gphatstaff000000000000Data-Paginator-0.08 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.012. use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Pagination with Moose", "AUTHOR" => "Cory G Watson ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Data-Paginator", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Data::Paginator", "PREREQ_PM" => { "Moose" => 0, "MooseX::Types" => 0, "MooseX::Types::Moose" => 0 }, "TEST_REQUIRES" => { "Test::More" => 0, "strict" => 0 }, "VERSION" => "0.08", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Moose" => 0, "MooseX::Types" => 0, "MooseX::Types::Moose" => 0, "Test::More" => 0, "strict" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 01-basic.t100644000765000024 234412425055124 15636 0ustar00gphatstaff000000000000Data-Paginator-0.08/tuse Test::More; use Data::Paginator; { my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => 1, }); cmp_ok($pager->page_for(1), '==', 1, '1st item is on 1st page'); cmp_ok($pager->page_for(11), '==', 3, '11th item is on 3rd page'); cmp_ok($pager->page_for(9), '==', 3, '9th item is on 3rd page'); cmp_ok($pager->page_for(12), '==', 3, '12th item is on 3rd page'); cmp_ok($pager->page_for(24), '==', 6, '24th item is on 6th page'); ok(!defined($pager->page_for(-12)), '-12 is on no page'); ok(!defined($pager->page_for(112)), '112 is on no page'); } { my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => -1, }); cmp_ok($pager->current_page, '==', 1, '-1 current_page yields 1'); } { my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => 111, }); cmp_ok($pager->current_page, '==', 6, '111 current_page yields 6'); } done_testing;currpage.t100644000765000024 43712425055124 16130 0ustar00gphatstaff000000000000Data-Paginator-0.08/tuse Test::More; use Data::Paginator; my $pager = Data::Paginator->new({ total_entries => 24, entries_per_page => 4, # This means there will be 6 pages current_page => 1, }); $pager->current_page(12); cmp_ok($pager->current_page, '==', 1); done_testing;release-synopsis.t100644000765000024 45612425055124 17626 0ustar00gphatstaff000000000000Data-Paginator-0.08/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Synopsis"; plan skip_all => "Test::Synopsis required for testing synopses" if $@; all_synopsis_ok(); Data000755000765000024 012425055124 15163 5ustar00gphatstaff000000000000Data-Paginator-0.08/libPaginator.pm100644000765000024 1727212425055124 17636 0ustar00gphatstaff000000000000Data-Paginator-0.08/lib/Datapackage Data::Paginator; $Data::Paginator::VERSION = '0.08'; use Moose; # ABSTRACT: Pagination with Moose use Data::Paginator::Types qw(PositiveInt); use MooseX::Types::Moose qw(Maybe); has current_page => ( is => 'ro', isa => 'Num', default => 1 ); has current_set => ( is => 'ro', isa => Maybe[PositiveInt], lazy_build => 1 ); has entries_per_page => ( is => 'ro', isa => PositiveInt, required => 1 ); has last_page => ( is => 'ro', isa => PositiveInt, lazy_build => 1 ); has next_set => ( is => 'ro', isa => Maybe[PositiveInt], lazy_build => 1 ); has pages_per_set => ( is => 'ro', isa => Maybe[PositiveInt], predicate => 'has_pages_per_set' ); has previous_set => ( is => 'ro', isa => Maybe[PositiveInt], lazy_build => 1 ); has total_entries => ( is => 'ro', isa => PositiveInt, required => 1 ); # This facilitates incorrect page numbers. around 'current_page' => sub { my ($orig, $self) = @_; my $attr = $self->meta->find_attribute_by_name('current_page'); my $val = $attr->get_value($self); if(!defined($val)) { $attr->set_value($self, 1); return 1 } elsif($val < 1) { $attr->set_value($self, 1); return 1; } elsif($val > $self->last_page) { $attr->set_value($self, $self->last_page); return $self->last_page; } return $val; }; sub _build_current_set { my ($self) = @_; return $self->set_for($self->current_page); } sub _build_last_page { my ($self) = @_; my $pages = $self->total_entries / $self->entries_per_page; my $last_page; if ($pages == int $pages) { $last_page = $pages; } else { $last_page = 1 + int($pages); } $last_page = 1 if $last_page < 1; return $last_page; } sub _build_next_set { my ($self) = @_; return undef unless $self->pages_per_set; my $next = $self->current_set * ($self->pages_per_set * $self->entries_per_page) + 1; return undef if $next > $self->total_entries; return $next; } sub _build_previous_set { my ($self) = @_; return undef unless $self->pages_per_set; my $cset = $self->current_set; return undef if $cset == 1; return ($cset - 2) * $self->pages_per_set * $self->entries_per_page + 1; } sub entries_on_this_page { my ($self) = @_; if ($self->total_entries == 0) { return 0; } else { return $self->last - $self->first + 1; } } sub first { my ($self) = @_; if ($self->total_entries == 0) { return 0; } else { return (($self->current_page - 1) * $self->entries_per_page) + 1; } } sub first_page { my ($self) = @_; return 1; } sub first_set { my ($self) = @_; if($self->has_pages_per_set) { return 1; } return undef; } sub last { my $self = shift; if ($self->current_page == $self->last_page) { return $self->total_entries; } else { return ($self->current_page * $self->entries_per_page); } } sub next_page { my $self = shift; $self->current_page < $self->last_page ? $self->current_page + 1 : undef; } sub page_for { my ($self, $num) = @_; return undef if $num > $self->total_entries || $num < 1; my $page = $num / $self->entries_per_page; if($page > int($page)) { return int($page) + 1; } return $page; } sub previous_page { my ($self) = @_; if ($self->current_page > 1) { return $self->current_page - 1; } else { return undef; } } sub set_for { my ($self, $num) = @_; return undef unless $self->has_pages_per_set; my $set = $num / $self->pages_per_set; if(int($set) != $set) { return int($set) + 1; } return $set; } sub skipped { my $self = shift; my $skipped = $self->first - 1; return 0 if $skipped < 0; return $skipped; } sub splice { my ($self, $array) = @_; my $top = @$array > $self->last ? $self->last : @$array; return () if $top == 0; # empty return @{$array}[ $self->first - 1 .. $top - 1 ]; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Data::Paginator - Pagination with Moose =head1 VERSION version 0.08 =head1 SYNOPSIS use Data::Paginator; my $pager = Data::Paginator->new( current_page => 1, entries_per_page => 10, total_entries => 100, ); print "First page: ".$pager->first_page."\n"; print "Last page: ".$pager->last_page."\n"; print "First entry on page: ".$pager->first."\n"; print "Last entry on page: ".$pager->last."\n"; =head1 DESCRIPTION This is yet another pagination module. It only exists because none of the other pager modules are written using Moose. Sometimes there is a Moose feature – MooseX::Storage, in my case – that you need. It's a pain when you can't use it with an existing module. This module aims to be completely compatible with the venerable L. In fact, it's a pretty blatant copy of Data::Page, lifting code from some of it's methods. =head1 SETS This module provides behavior compatible with L, allowing you to break your pagination into sets. For example, if you have a large number of pages to show and would like to allow the user to 'jump' X pages at a time, you can set the C attribute to X and populate the links in your pagination control with the values from C and C. =head1 ATTRIBUTES =head2 current_page The current page. Defaults to 1. If you set this value to to a page number lesser than or greater than the range of the pager, then 1 or the last_page will be returned instead. It is safe to pass this numbers like -1000 or 1000 when there are only 3 pages. =head2 entries_per_page The number of entries per page, required at instantiation. =head2 last_page Returns the number of the last page. Lazily computed, so do not set. =head2 next_set Returns the number of the next set or undefined if there is no next. =head2 pages_per_set If you have a large number of pages to show and would like to allow the user to 'jump' X pages at a time, you can set the C attribute to X and populate the links in your pagination control with the values from C and C. =head2 previous_set Returns the set number of the previous set or undefined if there is no previous set. =head2 total_entries The total number of entries this pager is covering. Required at instantiation. =head2 first Returns the number of the first entry on the current page. =head2 first_page Always returns 1. =head1 METHODS =head2 entries_on_this_page Returns the number of entries on this page. =head2 first_set Returns 1 if this Paginator has pages_per_set. Otherwise returns undef. =head2 last Returns the number of the last entry on the current page. =head2 next_page Returns the page number of the next page if one exists, otherwise returns false. =head2 page_for ($count) Returns the page number that the $count item appears on. Returns undef if $count is outside the bounds of this Paginator. =head2 previous_page Returns the page number of the previous page if one exists, otherwise returns undef. =head2 set_for $page Returns the set number of the specified page. Returns undef if the page exceeds the bounds of the Paginator. =head2 splice Takes in an arrayref and returns only the values which are on the current page. =head1 ACKNOWLEDGEMENTS Léon Brocard and his work on L. =head1 AUTHOR Cory G Watson =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Cory G Watson. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut release-pod-syntax.t100644000765000024 57012425055124 20042 0ustar00gphatstaff000000000000Data-Paginator-0.08/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Paginator000755000765000024 012425055124 17107 5ustar00gphatstaff000000000000Data-Paginator-0.08/lib/DataTypes.pm100644000765000024 135512425055124 20715 0ustar00gphatstaff000000000000Data-Paginator-0.08/lib/Data/Paginatorpackage Data::Paginator::Types; $Data::Paginator::Types::VERSION = '0.08'; use MooseX::Types -declare => [qw( PositiveInt )]; use MooseX::Types::Moose qw(Int); # ABSTRACT: Defines types used by Data::Paginator subtype PositiveInt, as Int, where { $_ >= 0 }, message { 'Number is not equal to or larger than 0' }; 1; __END__ =pod =encoding UTF-8 =head1 NAME Data::Paginator::Types - Defines types used by Data::Paginator =head1 VERSION version 0.08 =head1 AUTHOR Cory G Watson =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Cory G Watson. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut