line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Transpose::Iterator::Scalar; |
2
|
1
|
|
|
1
|
|
27965
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
876
|
use Moo; |
|
1
|
|
|
|
|
11365
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'Data::Transpose::Iterator::Base'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Data::Transpose::Iterator::Scalar - Scalar iterator for Data::Transpose. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This iterator extends L, but as |
14
|
|
|
|
|
|
|
argument to the constructor accepts a arrayref with scalar values. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Internally, the records are kept and returned as hashrefs. You can set |
17
|
|
|
|
|
|
|
the key of the hashrefs with with the C method. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $iter = Data::Transpose::Iterator::Scalar->new([1, 2, 3, 4, 5]); |
24
|
|
|
|
|
|
|
$iter->next; |
25
|
|
|
|
|
|
|
# return { value => 1 }; |
26
|
|
|
|
|
|
|
$iter->key('string'); |
27
|
|
|
|
|
|
|
$iter->next; |
28
|
|
|
|
|
|
|
# return { string => 2 }; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 ACCESSORS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 key |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Internally, the records are kept and returned as hashrefs. This |
35
|
|
|
|
|
|
|
accessor controls then name of the key. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has key => (is => 'rw', |
40
|
|
|
|
|
|
|
trigger => 1, |
41
|
|
|
|
|
|
|
default => sub { 'value' }); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _trigger_records { |
44
|
6
|
|
|
6
|
|
587
|
my ($self, $records) = @_; |
45
|
|
|
|
|
|
|
|
46
|
6
|
50
|
|
|
|
14
|
if (ref($records) eq 'ARRAY') { |
47
|
6
|
|
|
|
|
20
|
$self->_set_count(scalar @$records); |
48
|
6
|
|
|
|
|
8
|
@$records = map { { $self->key => $_ } } @$records; |
|
22
|
|
|
|
|
798
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
0
|
|
|
|
|
0
|
die "Arguments for records should be an arrayref.\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
|
|
52
|
$self->reset; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _trigger_key { |
58
|
4
|
|
|
4
|
|
2371
|
my ($self, $newkey) = @_; |
59
|
4
|
|
|
|
|
64
|
my $records = $self->records; |
60
|
4
|
|
|
|
|
57
|
foreach my $i (@$records) { |
61
|
11
|
|
|
|
|
26
|
my ($k, @unhandled) = keys %$i; |
62
|
11
|
50
|
|
|
|
21
|
die "One key expected, got " . join(" ", @unhandled) . " instead!" |
63
|
|
|
|
|
|
|
if @unhandled; |
64
|
11
|
|
|
|
|
69
|
$i->{$newkey} = delete $i->{$k}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |