| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Zipper; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
2
|
|
|
2
|
|
89446
|
$Data::Zipper::VERSION = '0.02'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Easily traverse and transform immutable data |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
19
|
use warnings FATAL => 'all'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
79
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use Carp 'confess'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
141
|
|
|
10
|
2
|
|
|
2
|
|
4692
|
use Class::MOP; |
|
|
2
|
|
|
|
|
388512
|
|
|
|
2
|
|
|
|
|
110
|
|
|
11
|
2
|
|
|
2
|
|
26
|
use Scalar::Util 'blessed'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
156
|
|
|
12
|
2
|
|
|
|
|
17
|
use Sub::Exporter -setup => { |
|
13
|
|
|
|
|
|
|
exports => [qw( zipper )] |
|
14
|
2
|
|
|
2
|
|
2308
|
}; |
|
|
2
|
|
|
|
|
7665
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub zipper { |
|
17
|
3
|
50
|
|
3
|
1
|
6253
|
my %args = @_ == 1 |
|
18
|
|
|
|
|
|
|
? ( focus => shift() ) |
|
19
|
|
|
|
|
|
|
: @_; |
|
20
|
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
9
|
my $data = $args{focus}; |
|
22
|
3
|
|
|
|
|
5
|
my $class; |
|
23
|
3
|
100
|
|
|
|
24
|
if(blessed($data)) { |
|
|
|
50
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
$class = 'Data::Zipper::MOP'; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
elsif(ref($data) eq 'HASH') { |
|
27
|
2
|
|
|
|
|
6
|
$class = 'Data::Zipper::Hash' |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
else { |
|
30
|
0
|
|
|
|
|
0
|
die 'Cannot zip ' . ref($data) . ' objects'; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
22
|
Class::MOP::load_class($class); |
|
34
|
3
|
|
|
|
|
446
|
return $class->new(%args); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__ |
|
41
|
|
|
|
|
|
|
=pod |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=encoding utf-8 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Data::Zipper - Easily traverse and transform immutable data |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package Person; |
|
52
|
|
|
|
|
|
|
use Moose; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has name => ( is => 'ro' ); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
package MyApp; |
|
57
|
|
|
|
|
|
|
use Data::Zipper 'zipper'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $person = Person->new( name => 'John' ) |
|
60
|
|
|
|
|
|
|
my $sally = zipper($person) |
|
61
|
|
|
|
|
|
|
->traverse('name')->set('Sally') |
|
62
|
|
|
|
|
|
|
->up |
|
63
|
|
|
|
|
|
|
->focus; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 zipper |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Create a zipper of the correct type, depending on the data given |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Oliver Charles |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Oliver Charles <oliver.g.charles@googlemail.com>. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
80
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
|