| 1 | package Statocles::Image; | ||||||||||||||||||||||||||||
| 2 | 101 | our $VERSION = '0.099'; | |||||||||||||||||||||||||||
| 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 | 101 | ▶ | use Statocles::Base 'Class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 101 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 15 | ▶ | coerce => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 34 | 15 | my ( $href ) = @_; | |||||||||||||||||||||||||||
| 35 | 15 | ▶ | if ( blessed $href && $href->isa( 'Mojo::Path' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($href) and $href->isa("Mojo::Path")
MC/DC50%1/2
builtin::blessed($href) and $href->isa("Mojo::Path")
builtin::blessed($href)
$href->isa("Mojo::Path")
Truth table66%2/3
A and B
A= builtin::blessed($href)B= $href->isa("Mojo::Path")
| |||||||||||||||||||||||||||||
| 36 | 1 | return $href->to_string; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 14 | return $href; | |||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||
| 40 | 101 | ); | |||||||||||||||||||||||||||
| 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 | 9 | ▶ | default => sub { '' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 101 | ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | #pod =attr width | ||||||||||||||||||||||||||||
| 58 | #pod | ||||||||||||||||||||||||||||
| 59 | #pod The width of the image, in pixels. | ||||||||||||||||||||||||||||
| 60 | #pod | ||||||||||||||||||||||||||||
| 61 | #pod =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 101 | 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 | 101 | 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 | 2 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | return !$_[0]->alt ? 'presentation' : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||
| 93 | 101 | ); | |||||||||||||||||||||||||||
| 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 | 12 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | 101 | ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 101 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||