source: main/trunk/greenstone2/perllib/cpan/Mojo/Asset.pm

Last change on this file was 32205, checked in by ak19, 6 years ago

First set of commits to do with implementing the new 'paged_html' output option of PDFPlugin that uses using xpdftools' new pdftohtml. So far tested only on Linux (64 bit), but things work there so I'm optimistically committing the changes since they work. 2. Committing the pre-built Linux binaries of XPDFtools for both 32 and 64 bit built by the XPDF group. 2. To use the correct bitness variant of xpdftools, setup.bash now exports the BITNESS env var, consulted by gsConvert.pl. 3. All the perl code changes to do with using xpdf tools' pdftohtml to generate paged_html and feed it in the desired form into GS(3): gsConvert.pl, PDFPlugin.pm and its parent ConvertBinaryPFile.pm have been modified to make it all work. xpdftools' pdftohtml generates a folder containing an html file and a screenshot for each page in a PDF (as well as an index.html linking to each page's html). However, we want a single html file that contains each individual 'page' html's content in a div, and need to do some further HTML style, attribute and structure modifications to massage the xpdftool output to what we want for GS. In order to parse and manipulate the HTML 'DOM' to do this, we're using the Mojo::DOM package that Dr Bainbridge found and which he's compiled up. Mojo::DOM is therefore also committed in this revision. Some further changes and some display fixes are required, but need to check with the others about that.

File size: 3.1 KB
Line 
1package Mojo::Asset;
2use Mojo::Base 'Mojo::EventEmitter';
3
4use Carp 'croak';
5
6has 'end_range';
7has start_range => 0;
8
9sub add_chunk { croak 'Method "add_chunk" not implemented by subclass' }
10sub contains { croak 'Method "contains" not implemented by subclass' }
11sub get_chunk { croak 'Method "get_chunk" not implemented by subclass' }
12
13sub is_file {undef}
14
15sub is_range { !!($_[0]->end_range || $_[0]->start_range) }
16
17sub move_to { croak 'Method "move_to" not implemented by subclass' }
18sub mtime { croak 'Method "mtime" not implemented by subclass' }
19sub size { croak 'Method "size" not implemented by subclass' }
20sub slurp { croak 'Method "slurp" not implemented by subclass' }
21sub to_file { croak 'Method "to_file" not implemented by subclass' }
22
231;
24
25=encoding utf8
26
27=head1 NAME
28
29Mojo::Asset - HTTP content storage base class
30
31=head1 SYNOPSIS
32
33 package Mojo::Asset::MyAsset;
34 use Mojo::Base 'Mojo::Asset';
35
36 sub add_chunk {...}
37 sub contains {...}
38 sub get_chunk {...}
39 sub move_to {...}
40 sub mtime {...}
41 sub size {...}
42 sub slurp {...}
43 sub to_file {...}
44
45=head1 DESCRIPTION
46
47L<Mojo::Asset> is an abstract base class for HTTP content storage backends,
48like L<Mojo::Asset::File> and L<Mojo::Asset::Memory>.
49
50=head1 EVENTS
51
52L<Mojo::Asset> inherits all events from L<Mojo::EventEmitter>.
53
54=head1 ATTRIBUTES
55
56L<Mojo::Asset> implements the following attributes.
57
58=head2 end_range
59
60 my $end = $asset->end_range;
61 $asset = $asset->end_range(8);
62
63Pretend file ends earlier.
64
65=head2 start_range
66
67 my $start = $asset->start_range;
68 $asset = $asset->start_range(3);
69
70Pretend file starts later.
71
72=head1 METHODS
73
74L<Mojo::Asset> inherits all methods from L<Mojo::EventEmitter> and implements
75the following new ones.
76
77=head2 add_chunk
78
79 $asset = $asset->add_chunk('foo bar baz');
80
81Add chunk of data to asset. Meant to be overloaded in a subclass.
82
83=head2 contains
84
85 my $position = $asset->contains('bar');
86
87Check if asset contains a specific string. Meant to be overloaded in a
88subclass.
89
90=head2 get_chunk
91
92 my $bytes = $asset->get_chunk($offset);
93 my $bytes = $asset->get_chunk($offset, $max);
94
95Get chunk of data starting from a specific position, defaults to a maximum
96chunk size of C<131072> bytes (128KiB). Meant to be overloaded in a subclass.
97
98=head2 is_file
99
100 my $bool = $asset->is_file;
101
102False, this is not a L<Mojo::Asset::File> object.
103
104=head2 is_range
105
106 my $bool = $asset->is_range;
107
108Check if asset has a L</"start_range"> or L</"end_range">.
109
110=head2 move_to
111
112 $asset = $asset->move_to('/home/sri/foo.txt');
113
114Move asset data into a specific file. Meant to be overloaded in a subclass.
115
116=head2 mtime
117
118 my $mtime = $asset->mtime;
119
120Modification time of asset. Meant to be overloaded in a subclass.
121
122=head2 size
123
124 my $size = $asset->size;
125
126Size of asset data in bytes. Meant to be overloaded in a subclass.
127
128=head2 slurp
129
130 my $bytes = $asset->slurp;
131
132Read all asset data at once. Meant to be overloaded in a subclass.
133
134=head2 to_file
135
136 my $file = $asset->to_file;
137
138Convert asset to L<Mojo::Asset::File> object. Meant to be overloaded in a
139subclass.
140
141=head1 SEE ALSO
142
143L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
144
145=cut
Note: See TracBrowser for help on using the repository browser.