line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Memento::Handler::Catmandu::Bag; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
51653
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
144560
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
873
|
use Catmandu; |
|
1
|
|
|
|
|
91464
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
218
|
use Catmandu::Util qw(is_string is_instance); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
504
|
use DateTime::Format::ISO8601; |
|
1
|
|
|
|
|
529366
|
|
|
1
|
|
|
|
|
66
|
|
10
|
1
|
|
|
1
|
|
12
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
11
|
1
|
|
|
1
|
|
440
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Plack::Middleware::Memento::Handler'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has store => (is => 'ro'); |
16
|
|
|
|
|
|
|
has bag => (is => 'ro'); # TODO type check |
17
|
|
|
|
|
|
|
has _bag => (is => 'lazy'); |
18
|
|
|
|
|
|
|
has _iso8601_date => (is => 'lazy'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build__bag { |
21
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
22
|
0
|
|
|
|
|
|
Catmandu->store($self->store)->bag($self->bag); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build__iso8601_date { |
26
|
0
|
|
|
0
|
|
|
DateTime::Format::ISO8601->new; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_all_mementos { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, $uri_r, $req) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my ($id) = $uri_r =~ m|([^/]+)$|; |
33
|
0
|
0
|
|
|
|
|
is_string($id) || return; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $bag = $self->_bag; |
36
|
0
|
|
0
|
|
|
|
my $versions = $bag->get_history($id) || return; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
[ map { |
39
|
0
|
|
|
|
|
|
my $version = $_; |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $dt = $self->_iso8601_date->parse_datetime($version->{$bag->datestamp_updated_key}); |
41
|
0
|
|
|
|
|
|
my $id = $version->{$bag->id_key}; |
42
|
0
|
|
|
|
|
|
my $version_id = $version->{$bag->version_key}; |
43
|
0
|
|
|
|
|
|
my $uri_m = $req->base; |
44
|
0
|
|
|
|
|
|
$uri_m->path("$id/versions/$version_id"); |
45
|
0
|
|
|
|
|
|
[$uri_m->canonical->as_string, $dt]; |
46
|
|
|
|
|
|
|
} @$versions ]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub wrap_memento_request { |
50
|
0
|
|
|
0
|
0
|
|
my ($self, $req) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my ($id, $version_id) = $req->path =~ m|^/([^/]+)/versions/([^/]+)$|; |
53
|
0
|
0
|
|
|
|
|
is_string($id) || return; |
54
|
0
|
0
|
|
|
|
|
is_string($version_id) || return; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $bag = $self->_bag; |
57
|
0
|
|
0
|
|
|
|
my $version = $bag->get_version($id, $version_id) || return; |
58
|
0
|
|
|
|
|
|
my $dt = $self->_iso8601_date->parse_datetime($version->{$bag->datestamp_updated_key}); |
59
|
0
|
|
|
|
|
|
my $uri_r = $req->base; |
60
|
0
|
|
|
|
|
|
$uri_r->path($id); |
61
|
0
|
|
|
|
|
|
return $uri_r->canonical->as_string, $dt; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub wrap_original_resource_request { |
65
|
0
|
|
|
0
|
0
|
|
my ($self, $req) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my ($id) = $req->path =~ m|^/([^/]+)$|; |
68
|
0
|
|
|
|
|
|
is_string($id); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=encoding utf-8 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Plack::Middleware::Memento::Handler::Catmandu::Bag - Connect Plack::App::Catmandu::Bag to Plack::Middleware::Memento |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
builder { |
83
|
|
|
|
|
|
|
enable 'Memento', handler => 'Catmandu::Bag', store => 'mystore', bag => 'mybag'; |
84
|
|
|
|
|
|
|
$app |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Nicolas Steenlant E<lt>nicolas.steenlant@ugent.beE<gt> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |