1 | package Mojo::Server::Morbo::Backend;
|
---|
2 | use Mojo::Base -base;
|
---|
3 |
|
---|
4 | use Carp 'croak';
|
---|
5 |
|
---|
6 | has watch => sub { [qw(lib templates)] };
|
---|
7 | has watch_timeout => sub { $ENV{MOJO_MORBO_TIMEOUT} || 1 };
|
---|
8 |
|
---|
9 | sub modified_files {
|
---|
10 | croak 'Method "modified_files" not implemented by subclass';
|
---|
11 | }
|
---|
12 |
|
---|
13 | 1;
|
---|
14 |
|
---|
15 | =encoding utf8
|
---|
16 |
|
---|
17 | =head1 NAME
|
---|
18 |
|
---|
19 | Mojo::Server::Morbo::Backend - Morbo backend base class
|
---|
20 |
|
---|
21 | =head1 SYNOPSIS
|
---|
22 |
|
---|
23 | package Mojo::Server::Morbo::Backend::Inotify:
|
---|
24 | use Mojo::Base 'Mojo::Server::Morbo::Backend';
|
---|
25 |
|
---|
26 | sub modified_files {...}
|
---|
27 |
|
---|
28 | =head1 DESCRIPTION
|
---|
29 |
|
---|
30 | L<Mojo::Server::Morbo::Backend> is an abstract base class for Morbo backends,
|
---|
31 | like L<Mojo::Server::Morbo::Backend::Poll>.
|
---|
32 |
|
---|
33 | =head1 ATTRIBUTES
|
---|
34 |
|
---|
35 | L<Mojo::Server::Morbo::Backend> implements the following attributes.
|
---|
36 |
|
---|
37 | =head2 watch
|
---|
38 |
|
---|
39 | my $watch = $backend->watch;
|
---|
40 | $backend = $backend->watch(['/home/sri/my_app']);
|
---|
41 |
|
---|
42 | Files and directories to watch for changes, defaults to the application script
|
---|
43 | as well as the C<lib> and C<templates> directories in the current working
|
---|
44 | directory.
|
---|
45 |
|
---|
46 | =head2 watch_timeout
|
---|
47 |
|
---|
48 | my $timeout = $backend->watch_timeout;
|
---|
49 | $backend = $backend->watch_timeout(10);
|
---|
50 |
|
---|
51 | Maximum amount of time in seconds a backend may block when waiting for files to
|
---|
52 | change, defaults to the value of the C<MOJO_MORBO_TIMEOUT> environment variable
|
---|
53 | or C<1>.
|
---|
54 |
|
---|
55 | =head1 METHODS
|
---|
56 |
|
---|
57 | L<Mojo::Server::Morbo::Backend> inherits all methods from L<Mojo::Base> and
|
---|
58 | implements the following new ones.
|
---|
59 |
|
---|
60 | =head2 modified_files
|
---|
61 |
|
---|
62 | my $files = $backend->modified_files;
|
---|
63 |
|
---|
64 | Check if files from L</"watch"> have been modified since the last check and
|
---|
65 | return an array reference with the results. Meant to be overloaded in a
|
---|
66 | subclass.
|
---|
67 |
|
---|
68 | # All files that have been modified
|
---|
69 | say for @{$backend->modified_files};
|
---|
70 |
|
---|
71 | =head1 SEE ALSO
|
---|
72 |
|
---|
73 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
|
---|
74 |
|
---|
75 | =cut
|
---|