| 1 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | package DBIx::DR::Iterator; | ||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use DBIx::DR::Util; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | # Perl 5.18 refuses smartmatch | ||||||||||||||||||||||||||||||||||||||||
| 12 | my $is = sub($$) { | ||||||||||||||||||||||||||||||||||||||||
| 13 | 14 | ▶ | my ($v1, $v2) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | return 0 if defined($v1) xor defined($v2); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
defined $v1 xor defined $v2
MC/DC0%0/2
defined $v1 xor defined $v2
defined $v1
defined $v2
Truth table25%1/4
A xor B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||
| 15 | 14 | ▶ | return 1 unless defined $v1; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 16 | 14 | return $v1 eq $v2; | |||||||||||||||||||||||||||||||||||||||
| 17 | 2 | }; | |||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||
| 20 | sub new { | ||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | my ($class, $fetch, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | my ($is_hash, $is_array) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | my $count; | |||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||
| 27 | 13 | ▶ | if ('ARRAY' eq ref $fetch) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | $is_array = 1; | |||||||||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | if ($count = @$fetch) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | croak 'You must use array of hashrefs' | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"HASH" eq ref $fetch->[0] or builtin::blessed($fetch->[0])
MC/DC0%0/2
"HASH" eq ref $fetch->[0] or builtin::blessed($fetch->[0])
"HASH" eq ref $fetch->[0]
builtin::blessed($fetch->[0])
Truth table66%2/3
A or B
A= "HASH" eq ref $fetch->[0]B= builtin::blessed($fetch->[0])
| |||||||||||||||||||||||||||||||||||||||||
| 31 | unless 'HASH' eq ref $fetch->[0] or blessed $fetch->[0]; | ||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||
| 33 | } elsif ('HASH' eq ref $fetch) { | ||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | $is_hash = 1; | |||||||||||||||||||||||||||||||||||||||
| 35 | 6 | my ($k) = each %$fetch; | |||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | if ($count = keys %$fetch) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 37 | croak 'You must use hash of hashrefs' | ||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | unless 'HASH' eq ref $fetch->{$k} or blessed $fetch->{$k}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"HASH" eq ref $fetch->{$k} or builtin::blessed($fetch->{$k})
MC/DC0%0/2
"HASH" eq ref $fetch->{$k} or builtin::blessed($fetch->{$k})
"HASH" eq ref $fetch->{$k}
builtin::blessed($fetch->{$k})
Truth table66%2/3
A or B
A= "HASH" eq ref $fetch->{$k}B= builtin::blessed($fetch->{$k})
| |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | croak "You should bless 'HASHREF' or 'ARRAYREF' value"; | |||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||
| 45 | my ($item_class, $item_constructor) = | ||||||||||||||||||||||||||||||||||||||||
| 46 | 13 | ▶ | camelize($opts{'-item'} || 'dbix-dr-iterator-item#new'); | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{'-item'} || 'dbix-dr-iterator-item#new'
MC/DC100%1/1
$opts{'-item'} || 'dbix-dr-iterator-item#new'
$opts{'-item'}
Truth table100%2/2
A
A= $opts{'-item'}
| |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | return bless { | ||||||||||||||||||||||||||||||||||||||||
| 50 | fetch => $fetch, | ||||||||||||||||||||||||||||||||||||||||
| 51 | is_hash => $is_hash, | ||||||||||||||||||||||||||||||||||||||||
| 52 | is_array => $is_array, | ||||||||||||||||||||||||||||||||||||||||
| 53 | count => $count, | ||||||||||||||||||||||||||||||||||||||||
| 54 | iterator => 0, | ||||||||||||||||||||||||||||||||||||||||
| 55 | item_class => $item_class, | ||||||||||||||||||||||||||||||||||||||||
| 56 | item_constructor => $item_constructor, | ||||||||||||||||||||||||||||||||||||||||
| 57 | is_changed => 0, | ||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ▶ | noitem_iter => $opts{-noitem_iter} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | } => ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | sub is_changed { | ||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_changed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | ▶ | $self->{is_changed} = $value ? 1 : 0 if @_ > 1; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | return $self->{is_changed}; | |||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||
| 71 | sub count { | ||||||||||||||||||||||||||||||||||||||||
| 72 | 22 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 73 | 22 | return $self->{count}; | |||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | sub reset { | ||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | $self->{iterator} = 0; | |||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | keys %{ $self->{fetch} } if $self->{is_hash}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | return; | |||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||
| 85 | sub next : method { | ||||||||||||||||||||||||||||||||||||||||
| 86 | 43 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||
| 88 | 43 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 89 | return $self->get($self->{iterator}++) | ||||||||||||||||||||||||||||||||||||||||
| 90 | 22 | ▶ | if $self->{iterator} < $self->{count}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | $self->{iterator} = 0; | |||||||||||||||||||||||||||||||||||||||
| 92 | 4 | return; | |||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||
| 95 | 21 | my ($k) = each %{ $self->{fetch} }; | |||||||||||||||||||||||||||||||||||||||
| 96 | 21 | ▶ | return unless defined $k; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 97 | 18 | return $self->get($k); | |||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||
| 101 | sub get { | ||||||||||||||||||||||||||||||||||||||||
| 102 | 88 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=11 SCAR=26.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 103 | 88 | ▶ | croak "Usage \$collection->get('name|number')" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ <= 1 or not defined $name
MC/DC0%0/2
@_ <= 1 or not defined $name
@_ <= 1
not defined $name
Truth table33%1/3
A or not(B)
A= @_ <= 1B= not defined $name
| |||||||||||||||||||||||||||||||||||||||||
| 104 | if @_ <= 1 or !defined($name); | ||||||||||||||||||||||||||||||||||||||||
| 105 | 88 | my $item; | |||||||||||||||||||||||||||||||||||||||
| 106 | 88 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 107 | 35 | ▶ | croak "Element number must be digit value" unless $name =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 108 | croak "Element number is out of arraybound" | ||||||||||||||||||||||||||||||||||||||||
| 109 | 35 | ▶ | if $name >= $self->{count} || $name < -$self->{count}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name >= $self->{"count"} or $name < -$self->{"count"}
MC/DC0%0/2
$name >= $self->{"count"} or $name < -$self->{"count"}
$name >= $self->{"count"}
$name < -$self->{"count"}
Truth table33%1/3
A or B
A= $name >= $self->{"count"}B= $name < -$self->{"count"}
| |||||||||||||||||||||||||||||||||||||||||
| 110 | 35 | $item = $self->{fetch}[ $name ]; | |||||||||||||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 112 | 53 | ▶ | croak "Key '$name' is not exists" unless exists $self->{fetch}{$name}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 113 | 53 | $item = $self->{fetch}{ $name }; | |||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||
| 116 | 88 | ▶ | unless(blessed $item) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 117 | 28 | ▶ | if (my $method = $self->{item_constructor}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 118 | $item = $self->{item_class}->$method( | ||||||||||||||||||||||||||||||||||||||||
| 119 | $item, | ||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | ▶ | ( $self->{noitem_iter} ? () : $self ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | bless $item => $self->{item_class}; | |||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||
| 126 | 88 | return $item; | |||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||
| 130 | sub exists { | ||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=8 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | ▶ | croak "Usage \$collection->exists('name|number')" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ <= 1 or not defined $name
MC/DC0%0/2
@_ <= 1 or not defined $name
@_ <= 1
not defined $name
Truth table33%1/3
A or not(B)
A= @_ <= 1B= not defined $name
| |||||||||||||||||||||||||||||||||||||||||
| 133 | if @_ <= 1 or !defined($name); | ||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | croak "Element number must be digit value" unless $name =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | return 0 if $name >= $self->{count} || $name < -$self->{count}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name >= $self->{"count"} or $name < -$self->{"count"}
MC/DC0%0/2
$name >= $self->{"count"} or $name < -$self->{"count"}
$name >= $self->{"count"}
$name < -$self->{"count"}
Truth table33%1/3
A or B
A= $name >= $self->{"count"}B= $name < -$self->{"count"}
| |||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | ▶ | return exists($self->{fetch}{$name}) || 0; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
exists $self->{'fetch'}{$name} || 0
MC/DC0%0/1
exists $self->{'fetch'}{$name} || 0
exists $self->{'fetch'}{$name}
Truth table50%1/2
A
A= exists $self->{'fetch'}{$name}
| |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||
| 145 | sub all { | ||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | ▶ | my ($self, $field) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 148 | 7 | my @res; | |||||||||||||||||||||||||||||||||||||||
| 149 | 7 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | ▶ | for (my $i = 0; $i < @{ $self->{fetch} }; $i++) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 151 | 15 | push @res => $self->get($i); | |||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | push @res => $self->get($_) for keys %{ $self->{fetch} }; | |||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | ▶ | @res = map { $_->$field } @res if $field; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | return @res; | |||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||
| 162 | sub grep : method { | ||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | my ($self, $key, $value) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
grep: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | my $cb; | |||||||||||||||||||||||||||||||||||||||
| 166 | 5 | ▶ | if ('CODE' eq ref $key) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | $cb = $key; | |||||||||||||||||||||||||||||||||||||||
| 168 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | $cb = sub { $is->($_[0]->$key, $value) }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||
| 172 | 5 | my $obj; | |||||||||||||||||||||||||||||||||||||||
| 173 | 5 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | $obj = [ grep { $cb->($_) } $self->all ]; | |||||||||||||||||||||||||||||||||||||||
| 175 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 176 | $obj = { | ||||||||||||||||||||||||||||||||||||||||
| 177 | 6 | map {( $_ => $self->get($_) )} | |||||||||||||||||||||||||||||||||||||||
| 178 | 15 | grep { $cb->( $self->get($_) ) } | |||||||||||||||||||||||||||||||||||||||
| 179 | 3 | keys %{ $self->{fetch} } | |||||||||||||||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||
| 183 | return $self->new( | ||||||||||||||||||||||||||||||||||||||||
| 184 | $obj, | ||||||||||||||||||||||||||||||||||||||||
| 185 | -item => decamelize($self->{item_class}, $self->{item_constructor}) | ||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | ); | |||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||
| 189 | sub first { | ||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | return ($self->{iterator} == 1) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | croak "'first' and 'last' methods aren't provided for hashiterators"; | |||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||
| 200 | sub last : method { | ||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
last: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ($self->{is_array}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | return ($self->{iterator} == $self->{count}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | croak "'first' and 'last' methods aren't provided for hashiterators"; | |||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||
| 212 | sub push : method { | ||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my ($self, $k, $v) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
push: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($self->{is_hash}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | croak 'Usage $it->push(key => $value)' unless @_ >= 3; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | croak 'Value is undefined' unless defined $v; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | croak "Value isn't HASHREF or object" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"HASH" eq ref $v or builtin::blessed($v)
MC/DC0%0/2
"HASH" eq ref $v or builtin::blessed($v)
"HASH" eq ref $v
builtin::blessed($v)
Truth table0%0/3
A or B
A= "HASH" eq ref $vB= builtin::blessed($v)
| |||||||||||||||||||||||||||||||||||||||||
| 219 | unless 'HASH' eq ref $v or blessed $v; | ||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $self->{count}++ unless exists $self->{fetch}{$k}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->{fetch}{$k} = $v; | |||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->is_changed(1); | |||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | croak "Value isn't defined" unless defined $k; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | croak "Value isn't HASHREF or object" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"HASH" eq ref $k or builtin::blessed($k)
MC/DC0%0/2
"HASH" eq ref $k or builtin::blessed($k)
"HASH" eq ref $k
builtin::blessed($k)
Truth table0%0/3
A or B
A= "HASH" eq ref $kB= builtin::blessed($k)
| |||||||||||||||||||||||||||||||||||||||||
| 228 | unless 'HASH' eq ref $k or blessed $k; | ||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | push @{ $self->{fetch} }, $k; | |||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $self->{count}++; | |||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||
| 234 | sub find : method { | ||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | ▶ | my ($self, $field, $value) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | $self->reset; | |||||||||||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | while(my $item = $self->next) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | return $item if $is->($item->$field, $value); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||
| 246 | package DBIx::DR::Iterator::Item; | ||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||
| 250 | # to exclude this method from AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||
| 251 | ▶ | sub DESTROY {} | |||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||
| 253 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
| 254 | 111 | ▶ | our $AUTOLOAD; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=12 SCAR=26.9
| |||||||||||||||||||||||||||||||||||||||||
| 255 | 111 | my ($method) = $AUTOLOAD =~ /.*::(.*)/; | |||||||||||||||||||||||||||||||||||||||
| 256 | 111 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||
| 258 | 111 | ▶ | Carp::croak "Can't find method '$self->$method'" unless ref $self; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 259 | Carp::croak "Can't find method '$method' in this item" | ||||||||||||||||||||||||||||||||||||||||
| 260 | 111 | ▶ | unless exists $self->{$method}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||
| 262 | 110 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | my $is_changed; | |||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||
| 265 | 4 | ▶ | if (ref $value and ref $self->{$method}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
ref $value and ref $self->{$method}
MC/DC100%2/2
ref $value and ref $self->{$method}
ref $value
ref $self->{$method}
Truth table100%3/3
A and B
A= ref $valueB= ref $self->{$method}
| |||||||||||||||||||||||||||||||||||||||||
| 266 | $is_changed = Scalar::Util::refaddr($value) | ||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | != Scalar::Util::refaddr($self->{$method}); | |||||||||||||||||||||||||||||||||||||||
| 268 | } elsif(ref($value) ne ref($self->{$method})) { | ||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | $is_changed = 1; | |||||||||||||||||||||||||||||||||||||||
| 270 | ▶ | } elsif(defined $value and defined $self->{$method}) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $value and defined $self->{$method}
MC/DC0%0/2
defined $value and defined $self->{$method}
defined $value
defined $self->{$method}
Truth table33%1/3
A and B
A= defined $valueB= defined $self->{$method}
| |||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | $is_changed = $value ne $self->{$method}; | |||||||||||||||||||||||||||||||||||||||
| 272 | ▶ | } elsif(defined $value xor defined $self->{$method}) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
defined $value xor defined $self->{$method}
MC/DC0%0/2
defined $value xor defined $self->{$method}
defined $value
defined $self->{$method}
Truth table0%0/4
A xor B
A= defined $valueB= defined $self->{$method}
| |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $is_changed = 1; | |||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||
| 276 | 4 | ▶ | $self->is_changed(1) if $is_changed; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 277 | 4 | $self->{$method} = $value; | |||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||
| 280 | 110 | return $self->{$method}; | |||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||
| 283 | sub new { | ||||||||||||||||||||||||||||||||||||||||
| 284 | 22 | ▶ | my ($class, $object, $iterator) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||
| 285 | 22 | ▶ | return unless defined $object; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 286 | 22 | ▶ | Carp::croak "Usage: DBIx::DR::Iterator::Item->new(HASHREF [, iterator ])" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 287 | unless 'HASH' eq ref $object; | ||||||||||||||||||||||||||||||||||||||||
| 288 | 22 | ▶ | my $self = bless $object => ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||
| 289 | 22 | $self->{iterator} = $iterator; | |||||||||||||||||||||||||||||||||||||||
| 290 | 22 | Scalar::Util::weaken($self->{iterator}); | |||||||||||||||||||||||||||||||||||||||
| 291 | 22 | $self->{is_changed} = 0; | |||||||||||||||||||||||||||||||||||||||
| 292 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||
| 295 | sub is_changed { | ||||||||||||||||||||||||||||||||||||||||
| 296 | 8 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_changed: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||
| 297 | 8 | ▶ | if (@_ > 1) {{ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | ▶ | $self->{is_changed} = $value ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | ▶ | last unless $self->{is_changed}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 301 | 3 | ▶ | last unless Scalar::Util::blessed $self->{iterator}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | ▶ | last unless $self->{iterator}->can('is_changed'); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | $self->{iterator}->is_changed( 1 ); | |||||||||||||||||||||||||||||||||||||||
| 304 | }} | ||||||||||||||||||||||||||||||||||||||||
| 305 | 8 | return $self->{is_changed}; | |||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||
| 308 | sub can { | ||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | my ($self, $method) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | return 1 if ref $self and exists $self->{$method}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self and exists $self->{$method}
MC/DC0%0/2
ref $self and exists $self->{$method}
ref $self
exists $self->{$method}
Truth table33%1/3
A and B
A= ref $selfB= exists $self->{$method}
| |||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | return $self->SUPER::can($method); | |||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||
| 317 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||
| 319 | DBIx::DR::Iterator - iterator for L<DBIx::DR>. | ||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||
| 321 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||
| 323 | my $it = DBIx::DR::Iterator->new($arrayref); | ||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||
| 325 | printf "Rows count: %d\n", $it->count; | ||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||
| 327 | while(my $row == $it->next) { | ||||||||||||||||||||||||||||||||||||||||
| 328 | print "Row: %s\n", $row->field; | ||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||
| 331 | my $row = $it->get(15); # element 15 | ||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||
| 335 | my $it = DBIx::DR::Iterator->new($hashref); | ||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||
| 337 | printf "Rows count: %d\n", $it->count; | ||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||
| 339 | while(my $row == $it->next) { | ||||||||||||||||||||||||||||||||||||||||
| 340 | print "Row: %s\n", $row->field; | ||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||
| 343 | my $row = $it->get('abc'); # element with key name eq 'abc' | ||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||
| 346 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||
| 348 | The package constructs iterator from HASHREF or ARRAYREF value. | ||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||
| 350 | =head1 Methods | ||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||
| 352 | =head2 new | ||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||
| 354 | Constructor. | ||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||
| 356 | my $i = DBIx::DR::Iterator->new($arrayset [, OPTIONS ]); | ||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||
| 358 | Where B<OPTIONS> are: | ||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||
| 360 | =over | ||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||
| 362 | =item -item => 'decamelized_obj_define'; | ||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||
| 364 | It will bless (or construct) row into specified class. See below. | ||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||
| 366 | By default it constructs L<DBIx::DR::Iterator::Item> objects. | ||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||
| 368 | =back | ||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||
| 370 | =head2 count | ||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||
| 372 | Returns count of elements. | ||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||
| 374 | =head2 is_changed | ||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||
| 376 | Returns (or set) flag that one of contained elements was changed. | ||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||
| 378 | =head2 exists(name|number) | ||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||
| 380 | Returns B<true> if element 'B<name|number>' is exists. | ||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||
| 382 | =head2 get(name|number) | ||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||
| 384 | Returns element by 'B<name|number>'. It will throw exception if element | ||||||||||||||||||||||||||||||||||||||||
| 385 | isn't L<exists|exists(name|number)>. | ||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||
| 387 | =head2 next | ||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||
| 389 | Returns next element or B<undef>. | ||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||
| 391 | =head2 reset | ||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||
| 393 | Resets internal iterator (that is used by L<next>). | ||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||
| 395 | =head2 all | ||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||
| 397 | Returns all elements (as an array). | ||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||
| 399 | If You notice an argument it will extract specified fields: | ||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||
| 401 | my @ids = $it->all('id'); | ||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||
| 403 | The same as: | ||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||
| 405 | my @ids = map { $_->id } $it->all; | ||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||
| 407 | =head2 grep | ||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||
| 409 | Constructs new iterator that is subset of parent iterator. | ||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||
| 411 | my $busy = $list->grep(sub { $_[0]->busy ? 1 : 0 }); | ||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||
| 413 | =head2 push | ||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||
| 415 | Pushes one element into iterator. | ||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||
| 417 | If You use HASH-iterator You have to note key name. | ||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||
| 419 | =head3 Example | ||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||
| 421 | $hiter->push(abc => { id => 1 }); | ||||||||||||||||||||||||||||||||||||||||
| 422 | $hiter->push(abc => $oiter->get('abc')); | ||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||
| 424 | $aiter->push({ id => 1 }); | ||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||
| 426 | =head1 DBIx::DR::Iterator::Item | ||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||
| 428 | One row. It has methods names coincident with field names. Also it has a few | ||||||||||||||||||||||||||||||||||||||||
| 429 | additional methods: | ||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||
| 431 | =head2 new | ||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||
| 433 | Constructor. Receives two arguments: B<HASHREF> and link to | ||||||||||||||||||||||||||||||||||||||||
| 434 | L<iterator|DBIx::DR::Iterator>. | ||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||
| 436 | my $row = DBIx::DR::Iterator::Item->new({ id => 1 }); | ||||||||||||||||||||||||||||||||||||||||
| 437 | $row = DBIx::DR::Iterator::Item->new({ id => 1 }, $iterator); } | ||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||
| 439 | =head2 iterator | ||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||
| 441 | Returns (or set) iterator object. The link is created by constructor. | ||||||||||||||||||||||||||||||||||||||||
| 442 | This is a L<weaken|Scalar::Util/weaken> link. | ||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||
| 444 | =head2 is_changed | ||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||
| 446 | Returns (or set) flag if the row has been changed. If You change any of | ||||||||||||||||||||||||||||||||||||||||
| 447 | row's fields the flag will be set. Also iterator's flag will be set. | ||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||
| 450 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||
| 452 | Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org> | ||||||||||||||||||||||||||||||||||||||||
| 453 | Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru> | ||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||
| 455 | This program is free software, you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||
| 456 | modify it under the terms of the Artistic License. | ||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||
| 458 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||