source: main/trunk/greenstone2/perllib/cpan/Mojo/Server/Morbo/Backend/Poll.pm@ 32205

Last change on this file since 32205 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: 1.6 KB
Line 
1package Mojo::Server::Morbo::Backend::Poll;
2use Mojo::Base 'Mojo::Server::Morbo::Backend';
3
4use Mojo::File 'path';
5
6sub modified_files {
7 my $self = shift;
8
9 my $cache = $self->{cache} ||= {};
10 my @files;
11 for my $file (map { -f $_ && -r _ ? $_ : _list($_) } @{$self->watch}) {
12 my ($size, $mtime) = (stat $file)[7, 9];
13 next unless defined $size and defined $mtime;
14 my $stats = $cache->{$file} ||= [$^T, $size];
15 next if $mtime <= $stats->[0] && $size == $stats->[1];
16 @$stats = ($mtime, $size);
17 push @files, $file;
18 }
19 sleep $self->watch_timeout unless @files;
20
21 return \@files;
22}
23
24sub _list { path(shift)->list_tree->map('to_string')->each }
25
261;
27
28=encoding utf8
29
30=head1 NAME
31
32Mojo::Server::Morbo::Backend::Poll - Morbo default backend
33
34=head1 SYNOPSIS
35
36 use Mojo::Server::Morbo::Backend::Poll;
37
38 my $backend = Mojo::Server::Morbo::Backend::Poll->new;
39 if (my $files = $backend->modified_files) {
40 ...
41 }
42
43=head1 DESCRIPTION
44
45L<Mojo::Server::Morbo::Backend:Poll> is the default backend for
46L<Mojo::Server::Morbo>.
47
48=head1 ATTRIBUTES
49
50L<Mojo::Server::Morbo::Backend::Poll> inherits all attributes from
51L<Mojo::Server::Morbo::Backend>.
52
53=head1 METHODS
54
55L<Mojo::Server::Morbo::Backend::Poll> inherits all methods from
56L<Mojo::Server::Morbo::Backend> and implements the following new ones.
57
58=head2 modified_files
59
60 my $files = $backend->modified_files;
61
62Check file size and mtime to determine which files have changed, this is not
63particularly efficient, but very portable.
64
65 # All files that have been modified
66 say for @{$backend->modified_files};
67
68=head1 SEE ALSO
69
70L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
71
72=cut
Note: See TracBrowser for help on using the repository browser.