| 1 | package Yukki::Model::FilePreview; | ||
| 2 | $Yukki::Model::FilePreview::VERSION = '0.991_002'; # TRIAL | ||
| 3 | |||
| 4 | $Yukki::Model::FilePreview::VERSION = '0.991002';use v5.24; | ||
| 5 | use utf8; | ||
| 6 | use Moo; | ||
| 7 | |||
| 8 | use Types::Standard qw( Str Int ); | ||
| 9 | |||
| 10 | use namespace::clean; | ||
| 11 | |||
| 12 | extends 'Yukki::Model::File'; | ||
| 13 | |||
| 14 | # ABSTRACT: a sub-class of the File model for handling previews | ||
| 15 | |||
| 16 | |||
| 17 | has content => ( | ||
| 18 | is => 'rw', | ||
| 19 | isa => Str, | ||
| 20 | required => 1, | ||
| 21 | ); | ||
| 22 | |||
| 23 | |||
| 24 | has position => ( | ||
| 25 | is => 'rw', | ||
| 26 | isa => Int, | ||
| 27 | required => 1, | ||
| 28 | default => -1, | ||
| 29 | ); | ||
| 30 | |||
| 31 | |||
| 32 | sub fetch { | ||
| 33 | my $self = shift; | ||
| 34 | return $self->content; | ||
| 35 | } | ||
| 36 | |||
| 37 | |||
| 38 | sub fetch_formatted { | ||
| 39 | my ($self, $ctx, $position) = @_; | ||
| 40 | $position //= $self->position; | ||
| 41 | return $self->SUPER::fetch_formatted($ctx, $position); | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 | |||
| 46 | __END__ | ||
| 47 | |||
| 48 | =pod | ||
| 49 | |||
| 50 | =encoding UTF-8 | ||
| 51 | |||
| 52 | =head1 NAME | ||
| 53 | |||
| 54 | Yukki::Model::FilePreview - a sub-class of the File model for handling previews | ||
| 55 | |||
| 56 | =head1 VERSION | ||
| 57 | |||
| 58 | version 0.991_002 | ||
| 59 | |||
| 60 | =head1 DESCRIPTION | ||
| 61 | |||
| 62 | This is a sub-class of L<Yukki::Model::File> that replaces the C<fetch> method with one that loads the content from a scalar attribute. | ||
| 63 | |||
| 64 | =head1 ATTRIBUTES | ||
| 65 | |||
| 66 | =head2 content | ||
| 67 | |||
| 68 | This is the content the file should have in the preview. | ||
| 69 | |||
| 70 | =head2 position | ||
| 71 | |||
| 72 | The position in the text for the caret. | ||
| 73 | |||
| 74 | =head1 METHODS | ||
| 75 | |||
| 76 | =head2 fetch | ||
| 77 | |||
| 78 | Returns the value of L</content>. | ||
| 79 | |||
| 80 | =head2 fetch_formatted | ||
| 81 | |||
| 82 | Same as in L<Yukki::Model::File>, except that the default position is L</position>. | ||
| 83 | |||
| 84 | =head1 AUTHOR | ||
| 85 | |||
| 86 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||
| 87 | |||
| 88 | =head1 COPYRIGHT AND LICENSE | ||
| 89 | |||
| 90 | This software is copyright (c) 2017 by Qubling Software LLC. | ||
| 91 | |||
| 92 | This is free software; you can redistribute it and/or modify it under | ||
| 93 | the same terms as the Perl 5 programming language system itself. | ||
| 94 | |||
| 95 | =cut |