line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package STF::Dispatcher::Impl::Hash; |
2
|
2
|
|
|
2
|
|
11972
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
3
|
2
|
|
|
2
|
|
11
|
use HTTP::Date (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
40
|
|
4
|
|
|
|
|
|
|
use Class::Accessor::Lite |
5
|
2
|
|
|
|
|
18
|
ro => [ qw(buckets) ] |
6
|
2
|
|
|
2
|
|
10
|
; |
|
2
|
|
|
|
|
3
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
5
|
my ($class, %args) = @_; |
10
|
1
|
|
|
|
|
10
|
bless{ buckets => {}, %args }, $class; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
30
|
|
|
30
|
0
|
233
|
sub start_request {} |
14
|
|
|
|
|
|
|
sub create_bucket { |
15
|
2
|
|
|
2
|
0
|
15
|
my ($self, $args) = @_; |
16
|
2
|
|
|
|
|
6
|
my $name = $args->{bucket_name}; |
17
|
2
|
|
|
|
|
11
|
$self->buckets->{$name} = { |
18
|
|
|
|
|
|
|
name => $name, |
19
|
|
|
|
|
|
|
objects => {}, |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_bucket { |
24
|
31
|
|
|
31
|
0
|
239
|
my ($self, $args) = @_; |
25
|
31
|
|
|
|
|
104
|
return $self->buckets->{$args->{bucket_name}}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub delete_bucket { |
29
|
1
|
|
|
1
|
0
|
180
|
my ($self, $args) = @_; |
30
|
1
|
|
|
|
|
5
|
delete $self->buckets->{$args->{bucket}->{name}}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub create_object { |
34
|
3
|
|
|
3
|
0
|
1042
|
my ($self, $args) = @_; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
13
|
my $object_name = $args->{object_name}; |
37
|
3
|
|
|
|
|
9
|
my $input = $args->{input}; |
38
|
3
|
|
|
|
|
8
|
my $content = $args->{content}; |
39
|
|
|
|
|
|
|
my $object = { |
40
|
|
|
|
|
|
|
modified_on => time(), |
41
|
|
|
|
|
|
|
content => $input ? |
42
|
3
|
50
|
|
|
|
11
|
do { local $/; <$input> } : |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
53
|
|
43
|
|
|
|
|
|
|
$content, |
44
|
|
|
|
|
|
|
}; |
45
|
3
|
50
|
|
|
|
16
|
$object->{content_type} = $args->{content_type} if $args->{content_type}; |
46
|
3
|
|
|
|
|
38
|
$args->{bucket}->{ $object_name } = STF::Dispatcher::Impl::Hash::Object->new( |
47
|
|
|
|
|
|
|
%$object |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub is_valid_object { |
52
|
6
|
|
|
6
|
0
|
49
|
my ($self, $args) = @_; |
53
|
6
|
|
|
|
|
28
|
return exists $args->{bucket}->{ $args->{object_name} }; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_object { |
57
|
9
|
|
|
9
|
0
|
1521
|
my ($self, $args) = @_; |
58
|
9
|
|
|
|
|
34
|
my $object = $args->{bucket}->{ $args->{object_name} }; |
59
|
9
|
100
|
|
|
|
30
|
return if (! $object ); |
60
|
|
|
|
|
|
|
|
61
|
6
|
100
|
|
|
|
25
|
if ( my $ims = $args->{request}->header('if-modified-since') ) { |
62
|
2
|
100
|
|
|
|
73
|
if ( $object->modified_on > HTTP::Date::str2time( $ims ) ) { |
63
|
1
|
|
|
|
|
73
|
STF::Dispatcher::PSGI::HTTPException->throw( 304, [], [] ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
5
|
|
|
|
|
172
|
return $object; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub modify_object { |
70
|
1
|
|
|
1
|
0
|
254
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub delete_object { |
74
|
1
|
|
|
1
|
0
|
8
|
my ($self, $args) = @_; |
75
|
1
|
|
|
|
|
7
|
delete $args->{bucket}->{ $args->{object_name} }; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub rename_bucket { |
79
|
2
|
|
|
2
|
0
|
21
|
my ($self, $args) = @_; |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
7
|
my $bucket = $args->{bucket}; |
82
|
2
|
|
|
|
|
6
|
my $name = $args->{name}; |
83
|
|
|
|
|
|
|
|
84
|
2
|
100
|
|
|
|
8
|
if ( $self->buckets->{ $name }) { |
85
|
1
|
|
|
|
|
12
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
1
|
|
|
|
|
11
|
$self->buckets->{ $name } = delete $self->buckets->{ $bucket->{name} }; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub rename_object { |
91
|
2
|
|
|
2
|
0
|
27
|
my ($self, $args) = @_; |
92
|
|
|
|
|
|
|
$args->{ destination_bucket }->{ $args->{ destination_object_name } } = |
93
|
2
|
|
|
|
|
18
|
delete $args->{source_bucket}->{ $args->{source_object_name} }; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package |
97
|
|
|
|
|
|
|
STF::Dispatcher::Impl::Hash::Object; |
98
|
2
|
|
|
2
|
|
3233
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
97
|
|
99
|
|
|
|
|
|
|
use Class::Accessor::Lite |
100
|
2
|
|
|
|
|
12
|
new => 1, |
101
|
|
|
|
|
|
|
ro => [ qw(content_type content modified_on) ] |
102
|
2
|
|
|
2
|
|
11
|
; |
|
2
|
|
|
|
|
3
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |