| 1 | # | ||||||||||||||||||||
| 2 | # Copyright (c) 2002-2006 | ||||||||||||||||||||
| 3 | # Steffen Müller <smueller@cpan.org> | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # All rights reserved. | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||
| 8 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 9 | # | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | package Data::Page::Tied; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | ▶ | use Data::Page; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | use vars qw/$VERSION @ISA/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | $VERSION = '2.01'; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | # inherit methods from Data::Page. | ||||||||||||||||||||
| 22 | 1 | push @ISA, 'Data::Page'; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # constructor | ||||||||||||||||||||
| 25 | 103 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 26 | 103 | my $proto = shift; | |||||||||||||||||||
| 27 | 103 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 28 | 103 | my $self = {}; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # get the data to start with | ||||||||||||||||||||
| 31 | 103 | my $entries = shift; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 103 | ▶ | if (ref $entries eq 'ARRAY') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | # if it's an array ref, we use its contents | ||||||||||||||||||||
| 35 | 69 | $self->{ENTRIES} = [ @{ $entries } ]; | |||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||
| 37 | # if it's not an array ref, we return a Data::Page object | ||||||||||||||||||||
| 38 | 34 | return Data::Page->new($entries, @_); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 69 | bless($self, $class); | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # set entries per page and current page (args) | ||||||||||||||||||||
| 44 | 69 | $self->set_entries_per_page(shift); | |||||||||||||||||||
| 45 | 69 | $self->set_current_page(shift); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 69 | return $self; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | # return the total number of entries. | ||||||||||||||||||||
| 51 | 311 | ▶ | sub total_entries { | ||||||||||||||||||
|
Subroutine
total_entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 52 | 311 | my $self = shift; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 311 | return scalar(@{$self->{ENTRIES}}); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # set the current page. | ||||||||||||||||||||
| 58 | 71 | ▶ | sub set_current_page { | ||||||||||||||||||
|
Subroutine
set_current_page: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 59 | 71 | my $o = shift()->current_page(@_); | |||||||||||||||||||
| 60 | 71 | $o->current_page(); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # set entries per page | ||||||||||||||||||||
| 64 | 71 | ▶ | sub set_entries_per_page { | ||||||||||||||||||
|
Subroutine
set_entries_per_page: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 65 | 71 | my $o = shift()->entries_per_page( @_ ); | |||||||||||||||||||
| 66 | 71 | return $o->entries_per_page; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # access an entry | ||||||||||||||||||||
| 70 | 68 | ▶ | sub entry { | ||||||||||||||||||
|
Subroutine
entry: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 71 | 68 | my $self = shift; | |||||||||||||||||||
| 72 | 68 | my $index = shift; | |||||||||||||||||||
| 73 | 68 | ▶ | $self->{ENTRIES}->[$index] = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 68 | return $self->{ENTRIES}->[$index]; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # set an entry | ||||||||||||||||||||
| 78 | 34 | ▶ | sub set_entry { | ||||||||||||||||||
|
Subroutine
set_entry: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 79 | 34 | shift()->entry(@_); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | ################## | ||||||||||||||||||||
| 83 | # tied interface # | ||||||||||||||||||||
| 84 | ################## | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | # invokes constructor | ||||||||||||||||||||
| 87 | 34 | ▶ | sub TIEARRAY { | ||||||||||||||||||
|
Subroutine
TIEARRAY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 88 | 34 | my $class = shift; | |||||||||||||||||||
| 89 | 34 | my $self = $class->new(@_); | |||||||||||||||||||
| 90 | 34 | return $self; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 105 | ▶ | sub FETCH { | ||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 94 | 105 | $_[0]->{ENTRIES}->[$_[1]]; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 34 | ▶ | sub STORE { | ||||||||||||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 98 | 34 | $_[0]->{ENTRIES}->[$_[1]] = $_[2]; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 77 | ▶ | sub FETCHSIZE { | ||||||||||||||||||
|
Subroutine
FETCHSIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 102 | 77 | my $self = shift; | |||||||||||||||||||
| 103 | 77 | return scalar @{$self->{ENTRIES}}; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 34 | ▶ | sub STORESIZE { | ||||||||||||||||||
|
Subroutine
STORESIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 107 | 34 | my $self = shift; | |||||||||||||||||||
| 108 | 34 | $#{$self->{ENTRIES}} = shift() - 1; | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | ▶ | sub EXTEND { | ||||||||||||||||||
|
Subroutine
EXTEND: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||
| 113 | 0 | $#{$self->{ENTRIES}} = shift() - 1; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 0 | ▶ | sub POP { pop @{ $_[0]->{ENTRIES} } } | ||||||||||||||||||
|
Subroutine
POP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | ▶ | sub PUSH { push @{ $_[0]->{ENTRIES} }, @_ } | ||||||||||||||||||
|
Subroutine
PUSH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | sub SHIFT { shift @{ $_[0]->{ENTRIES} } } | ||||||||||||||||||
|
Subroutine
SHIFT: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 0 | ▶ | sub UNSHIFT { unshift @{ $_[0]->{ENTRIES} }, @_ } | ||||||||||||||||||
|
Subroutine
UNSHIFT: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 0 | ▶ | sub SPLICE { splice @{ $_[0]->{ENTRIES} }, @_ } | ||||||||||||||||||
|
Subroutine
SPLICE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | ▶ | sub DELETE { $_[0]->{ENTRIES}->[$_[1]] = '' } | ||||||||||||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | sub EXISTS { croak "We don't do 'exists' here!" } | ||||||||||||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | ▶ | sub CLEAR { } | ||||||||||||||||||
|
Subroutine
CLEAR: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 1 | 1; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | __END__ | ||||||||||||||||||||