source: main/trunk/greenstone2/perllib/cpan/Mojolicious/Plugins.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: 4.7 KB
Line 
1package Mojolicious::Plugins;
2use Mojo::Base 'Mojo::EventEmitter';
3
4use Mojo::Loader 'load_class';
5use Mojo::Util 'camelize';
6
7has namespaces => sub { ['Mojolicious::Plugin'] };
8
9sub emit_chain {
10 my ($self, $name, @args) = @_;
11
12 my $wrapper;
13 for my $cb (reverse @{$self->subscribers($name)}) {
14 my $next = $wrapper;
15 $wrapper = sub { $cb->($next, @args) };
16 }
17
18 !$wrapper ? return : return $wrapper->();
19}
20
21sub emit_hook {
22 my $self = shift;
23 for my $cb (@{$self->subscribers(shift)}) { $cb->(@_) }
24 return $self;
25}
26
27sub emit_hook_reverse {
28 my $self = shift;
29 for my $cb (reverse @{$self->subscribers(shift)}) { $cb->(@_) }
30 return $self;
31}
32
33sub load_plugin {
34 my ($self, $name) = @_;
35
36 # Try all namespaces and full module name
37 my $suffix = $name =~ /^[a-z]/ ? camelize $name : $name;
38 my @classes = map {"${_}::$suffix"} @{$self->namespaces};
39 for my $class (@classes, $name) { return $class->new if _load($class) }
40
41 # Not found
42 die qq{Plugin "$name" missing, maybe you need to install it?\n};
43}
44
45sub register_plugin {
46 shift->load_plugin(shift)->register(shift, ref $_[0] ? $_[0] : {@_});
47}
48
49sub _load {
50 my $module = shift;
51 return $module->isa('Mojolicious::Plugin') unless my $e = load_class $module;
52 ref $e ? die $e : return undef;
53}
54
551;
56
57=encoding utf8
58
59=head1 NAME
60
61Mojolicious::Plugins - Plugin manager
62
63=head1 SYNOPSIS
64
65 use Mojolicious::Plugins;
66
67 my $plugins = Mojolicious::Plugins->new;
68 push @{$plugins->namespaces}, 'MyApp::Plugin';
69
70=head1 DESCRIPTION
71
72L<Mojolicious::Plugins> is the plugin manager of L<Mojolicious>.
73
74=head1 PLUGINS
75
76The following plugins are included in the L<Mojolicious> distribution as
77examples.
78
79=over 2
80
81=item L<Mojolicious::Plugin::Config>
82
83Perl-ish configuration files.
84
85=item L<Mojolicious::Plugin::DefaultHelpers>
86
87General purpose helper collection, loaded automatically.
88
89=item L<Mojolicious::Plugin::EPLRenderer>
90
91Renderer for plain embedded Perl templates, loaded automatically.
92
93=item L<Mojolicious::Plugin::EPRenderer>
94
95Renderer for more sophisticated embedded Perl templates, loaded automatically.
96
97=item L<Mojolicious::Plugin::HeaderCondition>
98
99Route condition for all kinds of headers, loaded automatically.
100
101=item L<Mojolicious::Plugin::JSONConfig>
102
103JSON configuration files.
104
105=item L<Mojolicious::Plugin::Mount>
106
107Mount whole L<Mojolicious> applications.
108
109=item L<Mojolicious::Plugin::PODRenderer>
110
111Renderer for turning POD into HTML and documentation browser for
112L<Mojolicious::Guides>.
113
114=item L<Mojolicious::Plugin::TagHelpers>
115
116Template specific helper collection, loaded automatically.
117
118=back
119
120=head1 EVENTS
121
122L<Mojolicious::Plugins> inherits all events from L<Mojo::EventEmitter>.
123
124=head1 ATTRIBUTES
125
126L<Mojolicious::Plugins> implements the following attributes.
127
128=head2 namespaces
129
130 my $namespaces = $plugins->namespaces;
131 $plugins = $plugins->namespaces(['Mojolicious::Plugin']);
132
133Namespaces to load plugins from, defaults to L<Mojolicious::Plugin>.
134
135 # Add another namespace to load plugins from
136 push @{$plugins->namespaces}, 'MyApp::Plugin';
137
138=head1 METHODS
139
140L<Mojolicious::Plugins> inherits all methods from L<Mojo::EventEmitter> and
141implements the following new ones.
142
143=head2 emit_chain
144
145 $plugins->emit_chain('foo');
146 $plugins->emit_chain(foo => 123);
147
148Emit events as chained hooks.
149
150=head2 emit_hook
151
152 $plugins = $plugins->emit_hook('foo');
153 $plugins = $plugins->emit_hook(foo => 123);
154
155Emit events as hooks.
156
157=head2 emit_hook_reverse
158
159 $plugins = $plugins->emit_hook_reverse('foo');
160 $plugins = $plugins->emit_hook_reverse(foo => 123);
161
162Emit events as hooks in reverse order.
163
164=head2 load_plugin
165
166 my $plugin = $plugins->load_plugin('some_thing');
167 my $plugin = $plugins->load_plugin('SomeThing');
168 my $plugin = $plugins->load_plugin('MyApp::Plugin::SomeThing');
169
170Load a plugin from the configured namespaces or by full module name.
171
172=head2 register_plugin
173
174 $plugins->register_plugin('some_thing', Mojolicious->new);
175 $plugins->register_plugin('some_thing', Mojolicious->new, foo => 23);
176 $plugins->register_plugin('some_thing', Mojolicious->new, {foo => 23});
177 $plugins->register_plugin('SomeThing', Mojolicious->new);
178 $plugins->register_plugin('SomeThing', Mojolicious->new, foo => 23);
179 $plugins->register_plugin('SomeThing', Mojolicious->new, {foo => 23});
180 $plugins->register_plugin('MyApp::Plugin::SomeThing', Mojolicious->new);
181 $plugins->register_plugin(
182 'MyApp::Plugin::SomeThing', Mojolicious->new, foo => 23);
183 $plugins->register_plugin(
184 'MyApp::Plugin::SomeThing', Mojolicious->new, {foo => 23});
185
186Load a plugin from the configured namespaces or by full module name and run
187C<register>, optional arguments are passed through.
188
189=head1 SEE ALSO
190
191L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
192
193=cut
Note: See TracBrowser for help on using the repository browser.