| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Whim; | 
| 2 | 2 |  |  | 2 |  | 1692 | use Mojo::Base 'Mojolicious'; | 
|  | 2 |  |  |  |  | 14 |  | 
|  | 2 |  |  |  |  | 27 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 2 |  |  | 2 |  | 159939 | use Mojo::File qw(curfile); | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 93 |  | 
| 5 | 2 |  |  | 2 |  | 23 | use Mojo::Loader qw(load_class); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 74 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 613 | use Whim::Core; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 61 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 13 | use Path::Tiny; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1314 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our $VERSION = '1.2023.04.06.0'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | has info => "This is Whim, version $VERSION, by Jason McIntosh."; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub startup { | 
| 16 | 3 |  |  | 3 | 1 | 73725 | my $self = shift; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # Switch the app's home to ~/.whim/ | 
| 19 |  |  |  |  |  |  | # (overridable by environment variable) | 
| 20 | 3 |  |  |  |  | 5 | my $whim_homedir; | 
| 21 | 3 | 50 |  |  |  | 18 | if ( defined $ENV{WHIM_HOME} ) { | 
| 22 | 3 |  |  |  |  | 21 | $whim_homedir = path( $ENV{WHIM_HOME} ); | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  | else { | 
| 25 | 0 |  |  |  |  | 0 | $whim_homedir = path( $ENV{HOME} )->child('.whim'); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 3 |  |  |  |  | 195 | $self->home( Mojo::Home->new($whim_homedir) ); | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 3 |  |  |  |  | 68 | my $config = | 
| 31 |  |  |  |  |  |  | $self->plugin( 'Config', { default => { home => $self->home, }, } ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 3 |  |  |  |  | 4552 | $self->commands->namespaces( ['Whim::Command'] ); | 
| 34 | 3 |  |  |  |  | 213 | $self->set_up_help; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # Create a 'whim' helper containing our Whim::Core object | 
| 37 |  |  |  |  |  |  | $self->helper( | 
| 38 |  |  |  |  |  |  | whim => sub { | 
| 39 | 2 |  |  | 2 |  | 1853 | state $whim = Whim::Core->new($config); | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 3 |  |  |  |  | 52 | ); | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | # Set up docroot and template paths. | 
| 44 |  |  |  |  |  |  | # For both, the first place to look is the app home, and then using | 
| 45 |  |  |  |  |  |  | # the library directory as a fallback. | 
| 46 | 3 |  |  |  |  | 257 | $self->static->paths( | 
| 47 |  |  |  |  |  |  | [   $self->home->child('public'), | 
| 48 |  |  |  |  |  |  | curfile->sibling('Whim')->child('public'), | 
| 49 |  |  |  |  |  |  | ] | 
| 50 |  |  |  |  |  |  | ); | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 3 |  |  |  |  | 636 | $self->renderer->paths( | 
| 53 |  |  |  |  |  |  | [   $self->home->child('templates'), | 
| 54 |  |  |  |  |  |  | curfile->sibling('Whim')->child('templates'), | 
| 55 |  |  |  |  |  |  | ] | 
| 56 |  |  |  |  |  |  | ); | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | # Set up routes for the listener | 
| 59 | 3 |  |  |  |  | 497 | my $r = $self->routes; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 3 |  |  |  |  | 47 | $r->get('/')->to('listen#default'); | 
| 62 | 3 |  |  |  |  | 1074 | $r->post('/')->to('listen#receive'); | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 3 |  |  |  |  | 643 | $r->get('/display_wms')->to('display#display'); | 
| 65 | 3 |  |  |  |  | 1051 | $r->get('/summarize_wms')->to('display#summarize'); | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | # Mojolicious's 'Unknown command' error message is confusing, so | 
| 68 |  |  |  |  |  |  | # we do our own check for command-knownness. | 
| 69 |  |  |  |  |  |  | # (Mojo's load_class(), invoked below, returns truth if it fails.) | 
| 70 | 3 | 0 | 33 |  |  | 1057 | if (   $ARGV[0] | 
|  |  |  | 33 |  |  |  |  | 
| 71 |  |  |  |  |  |  | && $ARGV[0] ne 'help' | 
| 72 |  |  |  |  |  |  | && load_class("Whim::Command::$ARGV[0]") ) | 
| 73 |  |  |  |  |  |  | { | 
| 74 | 0 |  |  |  |  | 0 | die "Unknown command '$ARGV[0]'. " | 
| 75 |  |  |  |  |  |  | . "(Type 'whim help' for a command list.)\n"; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub set_up_help { | 
| 80 | 3 |  |  | 3 | 0 | 7 | my $self = shift; | 
| 81 | 3 |  |  |  |  | 9 | $self->commands->message( $self->info . "\n\nAvailable commands:\n" ); | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 3 |  |  |  |  | 69 | $self->commands->hint( | 
| 84 |  |  |  |  |  |  | "\nSee 'whim help COMMAND' for more information on a specific " | 
| 85 |  |  |  |  |  |  | . "commmand.\n" | 
| 86 |  |  |  |  |  |  | . "See 'man whim' for more thorough documentation.\n" ); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | 1; | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head1 NAME | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | Whim - A code library used by the Whim webmention multitool | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | This is a code library used by the C<whim> executable. It doesn't have a | 
| 98 |  |  |  |  |  |  | public interface! | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | L<whim> | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head1 AUTHOR | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | Jason McIntosh E<lt>jmac@jmac.orgE<gt> |