source: main/trunk/greenstone2/perllib/cpan/Mojolicious/Plugin/Mount.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: 2.1 KB
Line 
1package Mojolicious::Plugin::Mount;
2use Mojo::Base 'Mojolicious::Plugin';
3
4use Mojo::Server;
5
6sub register {
7 my ($self, $app, $conf) = @_;
8
9 my $path = (keys %$conf)[0];
10 my $embed = Mojo::Server->new->load_app($conf->{$path});
11 $embed->secrets($app->secrets);
12
13 # Extract host
14 my $host;
15 ($host, $path) = ($1 ? qr/^(?:.*\.)?\Q$2\E$/i : qr/^\Q$2\E$/i, $3)
16 if $path =~ m!^(\*\.)?([^/]+)(/.*)?$!;
17
18 my $route = $app->routes->route($path)->detour(app => $embed);
19 return $host ? $route->over(host => $host) : $route;
20}
21
221;
23
24=encoding utf8
25
26=head1 NAME
27
28Mojolicious::Plugin::Mount - Application mount plugin
29
30=head1 SYNOPSIS
31
32 # Mojolicious
33 my $route = $app->plugin(Mount => {'/prefix' => '/home/sri/myapp.pl'});
34
35 # Mojolicious::Lite
36 my $route = plugin Mount => {'/prefix' => '/home/sri/myapp.pl'};
37
38 # Adjust the generated route and mounted application
39 my $example = plugin Mount => {'/example' => '/home/sri/example.pl'};
40 $example->to(message => 'It works great!');
41 my $app = $example->pattern->defaults->{app};
42 $app->config(foo => 'bar');
43 $app->log(app->log);
44
45 # Mount application with host
46 plugin Mount => {'example.com' => '/home/sri/myapp.pl'};
47
48 # Host and path
49 plugin Mount => {'example.com/myapp' => '/home/sri/myapp.pl'};
50
51 # Or even hosts with wildcard subdomains
52 plugin Mount => {'*.example.com/myapp' => '/home/sri/myapp.pl'};
53
54=head1 DESCRIPTION
55
56L<Mojolicious::Plugin::Mount> is a plugin that allows you to mount whole
57L<Mojolicious> applications.
58
59The code of this plugin is a good example for learning to build new plugins,
60you're welcome to fork it.
61
62See L<Mojolicious::Plugins/"PLUGINS"> for a list of plugins that are available
63by default.
64
65=head1 METHODS
66
67L<Mojolicious::Plugin::Mount> inherits all methods from L<Mojolicious::Plugin>
68and implements the following new ones.
69
70=head2 register
71
72 my $route = $plugin->register(Mojolicious->new, {'/foo' => '/some/app.pl'});
73
74Mount L<Mojolicious> application and return the generated route, which is
75usually a L<Mojolicious::Routes::Route> object.
76
77=head1 SEE ALSO
78
79L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
80
81=cut
Note: See TracBrowser for help on using the repository browser.