line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Content object class |
2
|
|
|
|
|
|
|
package Catalyst::Controller::SimpleCAS::Content; |
3
|
1
|
|
|
1
|
|
5
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4463
|
use Email::MIME; |
|
1
|
|
|
|
|
37071
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
492
|
use Image::Size; |
|
1
|
|
|
|
|
2928
|
|
|
1
|
|
|
|
|
536
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'Store', is => 'ro', required => 1, isa => 'Object'; |
9
|
|
|
|
|
|
|
has 'checksum', is => 'ro', required => 1, isa => 'Str'; |
10
|
|
|
|
|
|
|
has 'filename', is => 'ro', isa => 'Maybe[Str]', default => undef; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub BUILD { |
13
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
14
|
0
|
0
|
|
|
|
|
die "Content does not exist" unless ($self->Store->content_exists($self->checksum)); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'MIME' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
lazy => 1, |
20
|
|
|
|
|
|
|
default => sub { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $attrs = { |
24
|
|
|
|
|
|
|
content_type => $self->mimetype, |
25
|
|
|
|
|
|
|
encoding => 'base64' |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
$attrs = { %$attrs, |
28
|
|
|
|
|
|
|
filename => $self->filename, |
29
|
|
|
|
|
|
|
name => $self->filename |
30
|
|
|
|
|
|
|
} if ($self->filename); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return Email::MIME->create( |
33
|
|
|
|
|
|
|
attributes => scalar $attrs, |
34
|
|
|
|
|
|
|
body => scalar $self->content |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'mimetype' => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
lazy => 1, |
43
|
|
|
|
|
|
|
default => sub { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
return $self->Store->content_mimetype($self->checksum); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'image_size' => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
lazy => 1, |
52
|
|
|
|
|
|
|
default => sub { |
53
|
|
|
|
|
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
my ($width,$height) = $self->Store->image_size($self->checksum); |
55
|
|
|
|
|
|
|
return [$width,$height]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has 'size' => ( |
61
|
|
|
|
|
|
|
is => 'ro', |
62
|
|
|
|
|
|
|
lazy => 1, |
63
|
|
|
|
|
|
|
default => sub { |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
return $self->Store->content_size($self->checksum); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# TODO: abstract this properly and put it in the right place |
70
|
|
|
|
|
|
|
has 'fetch_url_path', is => 'ro', isa => 'Str', default => '/simplecas/fetch_content/'; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
has 'src_url', is => 'ro', lazy => 1, default => sub { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
my $url = $self->fetch_url_path . $self->checksum; |
75
|
|
|
|
|
|
|
$url .= '/' . $self->filename if ($self->filename); |
76
|
|
|
|
|
|
|
return $url; |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
has 'file_ext', is => 'ro', lazy => 1, default => sub { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
return undef unless ($self->filename); |
82
|
|
|
|
|
|
|
my @parts = split(/\./,$self->filename); |
83
|
|
|
|
|
|
|
return undef unless (scalar @parts > 1); |
84
|
|
|
|
|
|
|
return lc(pop @parts); |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has 'filelink_css_class', is => 'ro', lazy => 1, default => sub { |
88
|
|
|
|
|
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
my @css_class = ('filelink'); |
90
|
|
|
|
|
|
|
push @css_class, $self->file_ext if ($self->file_ext); |
91
|
|
|
|
|
|
|
return join(' ',@css_class); |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
has 'filelink', is => 'ro', lazy => 1, default => sub { |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
my $name = $self->filename || $self->checksum; |
97
|
|
|
|
|
|
|
return '<a class="' . $self->filelink_css_class . '" ' . |
98
|
|
|
|
|
|
|
' href="' . $self->src_url . '">' . $name . '</a>'; |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has 'img_size', is => 'ro', lazy => 1, default => sub { |
102
|
|
|
|
|
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $content_type = $self->mimetype or return undef; |
105
|
|
|
|
|
|
|
my ($mime_type,$mime_subtype) = split(/\//,$content_type); |
106
|
|
|
|
|
|
|
return undef unless ($mime_type eq 'image'); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my ($width,$height) = imgsize($self->Store->checksum_to_path($self->checksum)) or return undef; |
109
|
|
|
|
|
|
|
#return ($width,$height); |
110
|
|
|
|
|
|
|
return { height => $height, width => $width }; |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
has 'imglink', is => 'ro', lazy => 1, default => sub { |
114
|
|
|
|
|
|
|
my $self = shift; |
115
|
|
|
|
|
|
|
return undef unless ($self->img_size); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return '<img src="' . $self->src_url . '" ' . |
118
|
|
|
|
|
|
|
'height=' . $self->img_size->{height} . ' ' . |
119
|
|
|
|
|
|
|
'width=' . $self->img_size->{width} . ' ' . |
120
|
|
|
|
|
|
|
'>'; |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub fh { |
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
return $self->Store->fetch_content_fh($self->checksum); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub content { |
129
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
130
|
0
|
|
|
|
|
|
return $self->Store->fetch_content($self->checksum); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Catalyst::Controller::SimpleCAS::Content - Content object class for SimpleCAS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SYNOPSIS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
use Catalyst::Controller::SimpleCAS; |
144
|
|
|
|
|
|
|
... |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DESCRIPTION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This object class is used to represent an individual content entity within a SimpleCAS Store. |
149
|
|
|
|
|
|
|
This is used internally and is not meant to be called/used directly. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 Store |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 checksum |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 filename |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 MIME |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 mimetype |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 image_size |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 size |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 fetch_url_path |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 src_url |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 file_ext |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 filelink_css_class |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 filelink |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 img_size |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 imglink |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 METHODS |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 content |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 fh |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L<Catalyst::Controller::SimpleCAS> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=back |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 AUTHOR |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Henry Van Styn <vanstyn@cpan.org> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This software is copyright (c) 2014 by IntelliTree Solutions llc. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
207
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |