File Coverage

blib/lib/Renard/Incunabula/Document/Role/Pageable.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition 2 3 100.0
subroutine 7 7 100.0
pod n/a
total 36 37 100.0


line stmt bran cond sub pod time code
1 1     1   9445 use Renard::Incunabula::Common::Setup;
  1         2  
  1         12  
2             package Renard::Incunabula::Document::Role::Pageable;
3             # ABSTRACT: Role for documents that have numbered pages
4             $Renard::Incunabula::Document::Role::Pageable::VERSION = '0.005';
5 1     1   6344 use Moo::Role;
  1         3  
  1         7  
6 1     1   527 use Renard::Incunabula::Common::Types qw(Bool);
  1         14  
  1         17  
7 1     1   1500 use Renard::Incunabula::Document::Types qw(PageNumber PageCount);
  1         3  
  1         10  
8 1     1   1369 use MooX::ShortHas;
  1         2857  
  1         5  
9              
10             has first_page_number => (
11             is => 'ro',
12             isa => PageNumber,
13             default => 1,
14             );
15              
16              
17             has last_page_number => (
18             is => 'lazy', # _build_last_page_number
19             isa => PageNumber,
20             );
21              
22 9         7300 method is_valid_page_number( $page_number ) :ReturnType(Bool) {
  9         18  
  9         12  
23             # uncoverable condition right
24 9 100 66     25 PageNumber->check($page_number)
25             && $page_number >= $self->first_page_number
26             && $page_number <= $self->last_page_number
27 1     1   338 }
  1         2  
  1         8  
28              
29 1     1   392 lazy number_of_pages => method() {
  1         2  
30 1         24 (PageCount)->(
31             $self->last_page_number - $self->first_page_number + 1
32             );
33             }, isa => PageCount;
34              
35              
36             1;
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Renard::Incunabula::Document::Role::Pageable - Role for documents that have numbered pages
47              
48             =head1 VERSION
49              
50             version 0.005
51              
52             =head1 ATTRIBUTES
53              
54             =head2 first_page_number
55              
56             A C<PageNumber> containing the first page number of the document.
57             This is always C<1>.
58              
59             =head2 last_page_number
60              
61             A C<PageNumber> containing the last page number of the document.
62              
63             =head2 number_of_pages
64              
65             isa => PageCount
66              
67             Calculates the number of pages between the C<first_page_number> and C<last_page_number>.
68              
69             =head1 METHODS
70              
71             =head2 is_valid_page_number
72              
73             method is_valid_page_number( $page_number ) :ReturnType(Bool)
74              
75             Returns true if C<$page_number> is a valid C<PageNumber> and is between the
76             first and last page numbers inclusive.
77              
78             =head1 AUTHOR
79              
80             Project Renard
81              
82             =head1 COPYRIGHT AND LICENSE
83              
84             This software is copyright (c) 2017 by Project Renard.
85              
86             This is free software; you can redistribute it and/or modify it under
87             the same terms as the Perl 5 programming language system itself.
88              
89             =cut