| 1 | package Wishlist; | ||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base 'Mojolicious'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use File::Share; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Mojo::File; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Mojo::Home; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Mojo::SQLite; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use LinkEmbedder; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Wishlist::Model; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||
| 12 | 2 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | has dist_dir => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 2 | return Mojo::File->new( | |||||||||||||||||||||||||||||||||
| 16 | File::Share::dist_dir('Wishlist') | ||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||
| 18 | 2 | }; | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | has home => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 21 | 2 | my $home = $ENV{WISHLIST_HOME}; | |||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | return Mojo::Home->new($home ? $home : ())->to_abs; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 23 | 2 | }; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | has site_name => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 26 | 1 | my $app = shift; | |||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | return $app->config->{site_name} || 'Mojo Wishlist'; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$app->config->{'site_name'} || 'Mojo Wishlist'
MC/DC0%0/1
$app->config->{'site_name'} || 'Mojo Wishlist'
$app->config->{'site_name'}
Truth table50%1/2
A
A= $app->config->{'site_name'}
| |||||||||||||||||||||||||||||||||||
| 28 | 2 | }; | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | has sqlite => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.3
| |||||||||||||||||||||||||||||||||||
| 31 | 1 | my $app = shift; | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | # determine the storage location | ||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my $file = $app->config->{database} || 'wishlist.db'; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$app->config->{'database'} || 'wishlist.db'
MC/DC0%0/1
$app->config->{'database'} || 'wishlist.db'
$app->config->{'database'}
Truth table50%1/2
A
A= $app->config->{'database'}
| |||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | unless ($file =~ /^:/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | $file = Mojo::File->new($file); | |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | unless ($file->is_abs) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | $file = $app->home->child("$file"); | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 1 | my $sqlite = Mojo::SQLite->new | |||||||||||||||||||||||||||||||||
| 43 | ->from_filename("$file") | ||||||||||||||||||||||||||||||||||
| 44 | ->auto_migrate(1); | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | # attach migrations file | ||||||||||||||||||||||||||||||||||
| 47 | 1 | $sqlite->migrations->from_file( | |||||||||||||||||||||||||||||||||
| 48 | $app->dist_dir->child('wishlist.sql') | ||||||||||||||||||||||||||||||||||
| 49 | )->name('wishlist'); | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 1 | return $sqlite; | |||||||||||||||||||||||||||||||||
| 52 | 2 | }; | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub startup { | ||||||||||||||||||||||||||||||||
|
Subroutine
startup: called CC=2 SCAR=9.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 55 | 2 | my $app = shift; | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | $app->plugin('Config' => { | ||||||||||||||||||||||||||||||||||
| 58 | file => $ENV{WISHLIST_CONFIG}, | ||||||||||||||||||||||||||||||||||
| 59 | 2 | default => {}, | |||||||||||||||||||||||||||||||||
| 60 | }); | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | if (my $secrets = $app->config->{secrets}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 63 | 0 | $app->secrets($secrets); | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | $app->renderer->paths([ | ||||||||||||||||||||||||||||||||||
| 67 | 2 | $app->dist_dir->child('templates'), | |||||||||||||||||||||||||||||||||
| 68 | ]); | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $app->helper(link => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 71 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 72 | 0 | state $le = LinkEmbedder->new; | |||||||||||||||||||||||||||||||||
| 73 | 0 | return $le->get(@_); | |||||||||||||||||||||||||||||||||
| 74 | 2 | }); | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | $app->helper(model => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 77 | 1 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 78 | 1 | return Wishlist::Model->new( | |||||||||||||||||||||||||||||||||
| 79 | sqlite => $c->app->sqlite, | ||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||
| 81 | 2 | }); | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $app->helper(user => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($c, $username) = @_; | |||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $username ||= $c->stash->{username} || $c->session->{username}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$username ||= $c->stash->{"username"} || $c->session->{"username"}
$c->stash->{'username'} || $c->session->{'username'}
MC/DC0%0/3
$username ||= $c->stash->{"username"} || $c->session->{"username"}
$username
$c->stash->{'username'}
$c->session->{'username'}
Truth table0%0/4
A ||= B || C
A= $usernameB= $c->stash->{'username'}C= $c->session->{'username'}
| |||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return {} unless $username; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return $c->model->user($username) || {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->model->user($username) || {}
MC/DC0%0/1
$c->model->user($username) || {}
$c->model->user($username)
Truth table0%0/2
A
A= $c->model->user($username)
| |||||||||||||||||||||||||||||||||||
| 88 | 2 | }); | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $app->helper(users => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 91 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 92 | 0 | return $c->model->all_users; | |||||||||||||||||||||||||||||||||
| 93 | 2 | }); | |||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 2 | my $r = $app->routes; | |||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $r->get('/' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 97 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $template = $c->session->{username} ? 'list' : 'login'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | 0 | $c->render($template); | |||||||||||||||||||||||||||||||||
| 100 | 2 | }); | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 2 | $r->get('/list/:username')->to(template => 'list')->name('list'); | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 2 | $r->get('/add')->to('List#show_add')->name('show_add'); | |||||||||||||||||||||||||||||||||
| 105 | 2 | $r->post('/add')->to('List#do_add')->name('do_add'); | |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 2 | $r->post('/update')->to('List#update')->name('update'); | |||||||||||||||||||||||||||||||||
| 108 | 2 | $r->post('/remove')->to('List#remove')->name('remove'); | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 2 | $r->get('/register')->to(template => 'register')->name('show_register'); | |||||||||||||||||||||||||||||||||
| 111 | 2 | $r->post('/register')->to('Access#register')->name('do_register'); | |||||||||||||||||||||||||||||||||
| 112 | 2 | $r->post('/login')->to('Access#login')->name('login'); | |||||||||||||||||||||||||||||||||
| 113 | 2 | $r->any('/logout')->to('Access#logout')->name('logout'); | |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | Wishlist - A multi-user web application for tracking wanted items. | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | $ wishlist daemon | ||||||||||||||||||||||||||||||||||
| 126 | $ wishlist prefork | ||||||||||||||||||||||||||||||||||
| 127 | $ hypnotoad `which wishlist` | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | L<Wishlist> is a L<Mojolicious> application for storing and sharing wishlists derived from external urls. | ||||||||||||||||||||||||||||||||||
| 132 | Users paste urls and the app fetches data from those sites. | ||||||||||||||||||||||||||||||||||
| 133 | Users can then add the item to their wishlist. | ||||||||||||||||||||||||||||||||||
| 134 | Other users can then mark the item as purchased. | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | The application is very raw, lots of feature improvement is possible. | ||||||||||||||||||||||||||||||||||
| 137 | It was developed as examples from L<several of the posts|https://mojolicious.io/blog/tag/wishlist/> during the L<2017 Mojolicious Advent Calendar|https://mojolicious.io/blog/tag/advent/>. | ||||||||||||||||||||||||||||||||||
| 138 | I hope that it will continue to improve, with community collaboration, into a fully fledge competitor to cloud solutions that track and mine your data. | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | =head1 DEPLOYING | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | As L<Wishlist> is just a L<Mojolicious> application, all of the L<Mojolicious::Guides::Cookbook/DEPLOYMENT> options are available for deployment. | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | =head2 APPLICATION HOME | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | The application home is where L<Wishlist> stores data and looks for configuration. | ||||||||||||||||||||||||||||||||||
| 147 | It can be set by setting C<WISHLIST_HOME> in your environment, otherwise your current working directory is used. | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | =head2 CONFIGURATION | ||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||||
| 152 | site_name => 'Family Wishlist', | ||||||||||||||||||||||||||||||||||
| 153 | secrets => ['a very secret string'], | ||||||||||||||||||||||||||||||||||
| 154 | database => '/path/to/database/file.db', | ||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | A configuration file is highly recommended. | ||||||||||||||||||||||||||||||||||
| 158 | Its contents should evaluate to a Perl data structure. | ||||||||||||||||||||||||||||||||||
| 159 | The easiest usage is to create a configuration file in the L</"APPLICATION HOME">. | ||||||||||||||||||||||||||||||||||
| 160 | The file should be called C<wishlist.conf> or C<wishlist.$mode.conf> if per-mode configuration is desired. | ||||||||||||||||||||||||||||||||||
| 161 | Alternatively, an absolute path to the configuration file can be given via C<WISHLIST_CONFIG>. | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | The allowed configuration options are | ||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | =over | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | =item site_name | ||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | A string specifying the name of the site. | ||||||||||||||||||||||||||||||||||
| 170 | Used in the link to the application root. | ||||||||||||||||||||||||||||||||||
| 171 | Defaults to C<Mojo Wishlist>. | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | =item secrets | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | An array reference of strings used to sign storage cookies. | ||||||||||||||||||||||||||||||||||
| 176 | While this value is optional, it is highly recommended. | ||||||||||||||||||||||||||||||||||
| 177 | Learn about how these work at L<https://mojolicious.io/blog/2017/12/16/day-16-the-secret-life-of-sessions>. | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | =item database | ||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | Path to the file used to store data via L<Mojo::SQLite>. | ||||||||||||||||||||||||||||||||||
| 182 | If not specified the default value will be C<wishlist.db>. | ||||||||||||||||||||||||||||||||||
| 183 | Any relative values will be relative to the L</"APPLICATION HOME">. | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | =item hypnotoad | ||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | Hypnotoad uses the application's configuration for deployment parameters. | ||||||||||||||||||||||||||||||||||
| 188 | If you deploy using it, you probably should read L<Mojolicious::Guides::Cookbook/Hypnotoad>. | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | =back | ||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | =over | ||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | =item L<Blog entries tagged 'wishlist'|https://mojolicious.io/blog/tag/wishlist/> | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | =item L<Mojolicious> | ||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | =item L<LinkEmbedder> | ||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | =back | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | =head1 SOURCE REPOSITORY | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | L<http://github.com/jberger/Wishlist> | ||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | Joel Berger, E<lt>joel.a.berger@gmail.comE<gt> | ||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | =head1 CONTRIBUTORS | ||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | Nakayama Yasuhiro (yasu47b) | ||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | Copyright (C) 2017 by L</AUTHOR> and L</CONTRIBUTORS>. | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||