line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statocles::Image; |
2
|
|
|
|
|
|
|
our $VERSION = '0.086'; |
3
|
|
|
|
|
|
|
# ABSTRACT: A reference to an image |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
6
|
|
|
|
|
|
|
#pod |
7
|
|
|
|
|
|
|
#pod my $img = Statocles::Image->new( |
8
|
|
|
|
|
|
|
#pod src => '/path/to/image.jpg', |
9
|
|
|
|
|
|
|
#pod alt => 'Alternative text', |
10
|
|
|
|
|
|
|
#pod ); |
11
|
|
|
|
|
|
|
#pod |
12
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
13
|
|
|
|
|
|
|
#pod |
14
|
|
|
|
|
|
|
#pod This class holds a link to an image, and the attributes required to |
15
|
|
|
|
|
|
|
#pod render its markup. This is used by L<documents|Statocles::Document/images> |
16
|
|
|
|
|
|
|
#pod to associate images with the content. |
17
|
|
|
|
|
|
|
#pod |
18
|
|
|
|
|
|
|
#pod =cut |
19
|
|
|
|
|
|
|
|
20
|
68
|
|
|
68
|
|
450
|
use Statocles::Base 'Class'; |
|
68
|
|
|
|
|
146
|
|
|
68
|
|
|
|
|
547
|
|
21
|
68
|
|
|
68
|
|
463773
|
use Scalar::Util qw( blessed ); |
|
68
|
|
|
|
|
170
|
|
|
68
|
|
|
|
|
20988
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#pod =attr src |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod The source URL of the image. Required. |
26
|
|
|
|
|
|
|
#pod |
27
|
|
|
|
|
|
|
#pod =cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has src => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => Str, |
32
|
|
|
|
|
|
|
required => 1, |
33
|
|
|
|
|
|
|
coerce => sub { |
34
|
|
|
|
|
|
|
my ( $href ) = @_; |
35
|
|
|
|
|
|
|
if ( blessed $href && $href->isa( 'Path::Tiny' ) ) { |
36
|
|
|
|
|
|
|
return $href->stringify; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
return $href; |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#pod =attr alt |
43
|
|
|
|
|
|
|
#pod |
44
|
|
|
|
|
|
|
#pod The text to display if the image cannot be fetched or rendered. This is also |
45
|
|
|
|
|
|
|
#pod the text to use for non-visual media. |
46
|
|
|
|
|
|
|
#pod |
47
|
|
|
|
|
|
|
#pod If missing, the image is presentational only, not content. |
48
|
|
|
|
|
|
|
#pod |
49
|
|
|
|
|
|
|
#pod =cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has alt => ( |
52
|
|
|
|
|
|
|
is => 'rw', |
53
|
|
|
|
|
|
|
isa => Str, |
54
|
|
|
|
|
|
|
default => sub { '' }, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#pod =attr width |
58
|
|
|
|
|
|
|
#pod |
59
|
|
|
|
|
|
|
#pod The width of the image, in pixels. |
60
|
|
|
|
|
|
|
#pod |
61
|
|
|
|
|
|
|
#pod =cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has width => ( |
64
|
|
|
|
|
|
|
is => 'rw', |
65
|
|
|
|
|
|
|
isa => Int, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#pod =attr height |
69
|
|
|
|
|
|
|
#pod |
70
|
|
|
|
|
|
|
#pod The height of the image, in pixels. |
71
|
|
|
|
|
|
|
#pod |
72
|
|
|
|
|
|
|
#pod =cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
has height => ( |
75
|
|
|
|
|
|
|
is => 'rw', |
76
|
|
|
|
|
|
|
isa => Int, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#pod =attr role |
80
|
|
|
|
|
|
|
#pod |
81
|
|
|
|
|
|
|
#pod The L<ARIA|http://www.w3.org/TR/wai-aria/> role for this image. If the L</alt> |
82
|
|
|
|
|
|
|
#pod attribute is empty, this attribute defaults to C<"presentation">. |
83
|
|
|
|
|
|
|
#pod |
84
|
|
|
|
|
|
|
#pod =cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has role => ( |
87
|
|
|
|
|
|
|
is => 'rw', |
88
|
|
|
|
|
|
|
isa => Maybe[Str], |
89
|
|
|
|
|
|
|
lazy => 1, |
90
|
|
|
|
|
|
|
default => sub { |
91
|
|
|
|
|
|
|
return !$_[0]->alt ? 'presentation' : undef; |
92
|
|
|
|
|
|
|
}, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#pod =attr data |
96
|
|
|
|
|
|
|
#pod |
97
|
|
|
|
|
|
|
#pod A hash of arbitrary data available to theme templates. This is a good place to |
98
|
|
|
|
|
|
|
#pod put extra structured data like image credits, copyright, or location. |
99
|
|
|
|
|
|
|
#pod |
100
|
|
|
|
|
|
|
#pod =cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
has data => ( |
103
|
|
|
|
|
|
|
is => 'ro', |
104
|
|
|
|
|
|
|
isa => HashRef, |
105
|
|
|
|
|
|
|
default => sub { {} }, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=pod |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=encoding UTF-8 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Statocles::Image - A reference to an image |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 VERSION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
version 0.086 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SYNOPSIS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $img = Statocles::Image->new( |
127
|
|
|
|
|
|
|
src => '/path/to/image.jpg', |
128
|
|
|
|
|
|
|
alt => 'Alternative text', |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This class holds a link to an image, and the attributes required to |
134
|
|
|
|
|
|
|
render its markup. This is used by L<documents|Statocles::Document/images> |
135
|
|
|
|
|
|
|
to associate images with the content. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 src |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The source URL of the image. Required. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 alt |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The text to display if the image cannot be fetched or rendered. This is also |
146
|
|
|
|
|
|
|
the text to use for non-visual media. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
If missing, the image is presentational only, not content. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 width |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The width of the image, in pixels. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 height |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The height of the image, in pixels. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 role |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The L<ARIA|http://www.w3.org/TR/wai-aria/> role for this image. If the L</alt> |
161
|
|
|
|
|
|
|
attribute is empty, this attribute defaults to C<"presentation">. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 data |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
A hash of arbitrary data available to theme templates. This is a good place to |
166
|
|
|
|
|
|
|
put extra structured data like image credits, copyright, or location. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Doug Bell <preaction@cpan.org> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Doug Bell. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
177
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |