source: main/trunk/greenstone2/perllib/cpan/Mojolicious/Command/routes.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: 3.1 KB
Line 
1package Mojolicious::Command::routes;
2use Mojo::Base 'Mojolicious::Command';
3
4use re 'regexp_pattern';
5use Mojo::Util qw(encode getopt tablify);
6
7has description => 'Show available routes';
8has usage => sub { shift->extract_usage };
9
10sub run {
11 my ($self, @args) = @_;
12
13 getopt \@args, 'v|verbose' => \my $verbose;
14
15 my $rows = [];
16 _walk($_, 0, $rows, $verbose) for @{$self->app->routes->children};
17 print encode('UTF-8', tablify($rows));
18}
19
20sub _walk {
21 my ($route, $depth, $rows, $verbose) = @_;
22
23 # Pattern
24 my $prefix = '';
25 if (my $i = $depth * 2) { $prefix .= ' ' x $i . '+' }
26 push @$rows, my $row = [$prefix . ($route->pattern->unparsed || '/')];
27
28 # Flags
29 my @flags;
30 push @flags, @{$route->over || []} ? 'C' : '.';
31 push @flags, (my $partial = $route->partial) ? 'D' : '.';
32 push @flags, $route->inline ? 'U' : '.';
33 push @flags, $route->is_websocket ? 'W' : '.';
34 push @$row, join('', @flags) if $verbose;
35
36 # Methods
37 my $via = $route->via;
38 push @$row, !$via ? '*' : uc join ',', @$via;
39
40 # Name
41 my $name = $route->name;
42 push @$row, $route->has_custom_name ? qq{"$name"} : $name;
43
44 # Regex (verbose)
45 my $pattern = $route->pattern;
46 $pattern->match('/', $route->is_endpoint && !$partial);
47 push @$row, (regexp_pattern $pattern->regex)[0] if $verbose;
48
49 $depth++;
50 _walk($_, $depth, $rows, $verbose) for @{$route->children};
51 $depth--;
52}
53
541;
55
56=encoding utf8
57
58=head1 NAME
59
60Mojolicious::Command::routes - Routes command
61
62=head1 SYNOPSIS
63
64 Usage: APPLICATION routes [OPTIONS]
65
66 ./myapp.pl routes
67 ./myapp.pl routes -v
68
69 Options:
70 -h, --help Show this summary of available options
71 --home <path> Path to home directory of your application, defaults to
72 the value of MOJO_HOME or auto-detection
73 -m, --mode <name> Operating mode for your application, defaults to the
74 value of MOJO_MODE/PLACK_ENV or "development"
75 -v, --verbose Print additional details about routes, flags indicate
76 C=Conditions, D=Detour, U=Under and W=WebSocket
77
78=head1 DESCRIPTION
79
80L<Mojolicious::Command::routes> lists all your application routes.
81
82This is a core command, that means it is always enabled and its code a good
83example for learning to build new commands, you're welcome to fork it.
84
85See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are
86available by default.
87
88=head1 ATTRIBUTES
89
90L<Mojolicious::Command::routes> inherits all attributes from
91L<Mojolicious::Command> and implements the following new ones.
92
93=head2 description
94
95 my $description = $routes->description;
96 $routes = $routes->description('Foo');
97
98Short description of this command, used for the command list.
99
100=head2 usage
101
102 my $usage = $routes->usage;
103 $routes = $routes->usage('Foo');
104
105Usage information for this command, used for the help screen.
106
107=head1 METHODS
108
109L<Mojolicious::Command::routes> inherits all methods from
110L<Mojolicious::Command> and implements the following new ones.
111
112=head2 run
113
114 $routes->run(@ARGV);
115
116Run this command.
117
118=head1 SEE ALSO
119
120L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
121
122=cut
Note: See TracBrowser for help on using the repository browser.