| 1 | # Content object class | ||||||||||||||||||||
| 2 | package Catalyst::Controller::SimpleCAS::Content; | ||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use Email::MIME; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Image::Size; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | has 'Store', is => 'ro', required => 1, isa => 'Object'; | |||||||||||||||||||
| 9 | 1 | has 'checksum', is => 'ro', required => 1, isa => 'Str'; | |||||||||||||||||||
| 10 | 1 | has 'filename', is => 'ro', isa => 'Maybe[Str]', default => undef; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | sub BUILD { | ||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 13 | 0 | my $self = shift; | |||||||||||||||||||
| 14 | 0 | ▶ | die "Content does not exist" unless ($self->Store->content_exists($self->checksum)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | has 'MIME' => ( | ||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||
| 19 | lazy => 1, | ||||||||||||||||||||
| 20 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 21 | 0 | my $self = shift; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | my $attrs = { | |||||||||||||||||||
| 24 | content_type => $self->mimetype, | ||||||||||||||||||||
| 25 | encoding => 'base64' | ||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||
| 27 | 0 | ▶ | $attrs = { %$attrs, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | filename => $self->filename, | ||||||||||||||||||||
| 29 | name => $self->filename | ||||||||||||||||||||
| 30 | } if ($self->filename); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | return Email::MIME->create( | |||||||||||||||||||
| 33 | attributes => scalar $attrs, | ||||||||||||||||||||
| 34 | body => scalar $self->content | ||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | has 'mimetype' => ( | ||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||
| 42 | lazy => 1, | ||||||||||||||||||||
| 43 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||||||||||
| 45 | 0 | return $self->Store->content_mimetype($self->checksum); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | 1 | ); | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | has 'image_size' => ( | ||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||
| 51 | lazy => 1, | ||||||||||||||||||||
| 52 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||
| 54 | 0 | my ($width,$height) = $self->Store->image_size($self->checksum); | |||||||||||||||||||
| 55 | 0 | return [$width,$height]; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | 1 | ); | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | has 'size' => ( | ||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||
| 62 | lazy => 1, | ||||||||||||||||||||
| 63 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||
| 65 | 0 | return $self->Store->content_size($self->checksum); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 1 | ); | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # TODO: abstract this properly and put it in the right place | ||||||||||||||||||||
| 70 | 1 | has 'fetch_url_path', is => 'ro', isa => 'Str', default => '/simplecas/fetch_content/'; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | has 'src_url', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||||||||||
| 74 | 0 | my $url = $self->fetch_url_path . $self->checksum; | |||||||||||||||||||
| 75 | 0 | ▶ | $url .= '/' . $self->filename if ($self->filename); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | return $url; | |||||||||||||||||||
| 77 | 1 | }; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | has 'file_ext', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||
| 81 | 0 | ▶ | return undef unless ($self->filename); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | my @parts = split(/\./,$self->filename); | |||||||||||||||||||
| 83 | 0 | ▶ | return undef unless (scalar @parts > 1); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | return lc(pop @parts); | |||||||||||||||||||
| 85 | 1 | }; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | ▶ | has 'filelink_css_class', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||||||||||
| 89 | 0 | my @css_class = ('filelink'); | |||||||||||||||||||
| 90 | 0 | ▶ | push @css_class, $self->file_ext if ($self->file_ext); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 0 | return join(' ',@css_class); | |||||||||||||||||||
| 92 | 1 | }; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | ▶ | has 'filelink', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||
| 96 | 0 | ▶ | my $name = $self->filename || $self->checksum; | ||||||||||||||||||
|
Condition0%0/3
$self->filename || $self->checksum
MC/DC0%0/2
$self->filename || $self->checksum
$self->filename
$self->checksum
Truth table0%0/3
A || B
A= $self->filenameB= $self->checksum
| |||||||||||||||||||||
| 97 | 0 | return '<a class="' . $self->filelink_css_class . '" ' . | |||||||||||||||||||
| 98 | ' href="' . $self->src_url . '">' . $name . '</a>'; | ||||||||||||||||||||
| 99 | 1 | }; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | has 'img_size', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | ▶ | my $content_type = $self->mimetype or return undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 0 | my ($mime_type,$mime_subtype) = split(/\//,$content_type); | |||||||||||||||||||
| 106 | 0 | ▶ | return undef unless ($mime_type eq 'image'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | my ($width,$height) = imgsize($self->Store->checksum_to_path($self->checksum)) or return undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | #return ($width,$height); | ||||||||||||||||||||
| 110 | 0 | return { height => $height, width => $width }; | |||||||||||||||||||
| 111 | 1 | }; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | ▶ | has 'imglink', is => 'ro', lazy => 1, default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||
| 115 | 0 | ▶ | return undef unless ($self->img_size); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | return '<img src="' . $self->src_url . '" ' . | ||||||||||||||||||||
| 118 | 'height=' . $self->img_size->{height} . ' ' . | ||||||||||||||||||||
| 119 | 0 | 'width=' . $self->img_size->{width} . ' ' . | |||||||||||||||||||
| 120 | '>'; | ||||||||||||||||||||
| 121 | 1 | }; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | ▶ | sub fh { | ||||||||||||||||||
|
Subroutine
fh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||||||||
| 125 | 0 | return $self->Store->fetch_content_fh($self->checksum); | |||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | sub content { | ||||||||||||||||||
|
Subroutine
content: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||
| 130 | 0 | return $self->Store->fetch_content($self->checksum); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 1 | 1; | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||