File Coverage

blib/lib/App/MHFS.pm
Criterion Covered Total %
statement 17 38 44.7
branch 0 16 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 23 62 37.1


line stmt bran cond sub pod time code
1             package App::MHFS v0.7.0;
2 1     1   252175 use 5.014;
  1         5  
3 1     1   6 use strict; use warnings;
  1     1   3  
  1         30  
  1         6  
  1         2  
  1         58  
4 1     1   6 use feature 'say';
  1         2  
  1         199  
5 1     1   909 use Getopt::Long qw(GetOptions);
  1         16866  
  1         5  
6 1     1   919 use MHFS::HTTP::Server;
  1         6  
  1         591  
7             Getopt::Long::Configure qw(gnu_getopt);
8             our $VERSION;
9              
10             our $USAGE = "Usage: $0 ".<<'END_USAGE';
11             [-h|--help] [-v|--version] [--flush] [--cfgdir ] [--appdir ]
12             [--fallback_data_root ]
13             Media Http File Server - Stream your own music and video library via your
14             browser and standard media players.
15              
16             All options are optional, provided to override settings.pl and defaults
17             --flush turn on autoflush for STDOUT and STDERR
18             --cfgdir location of configuration directory, will be created if
19             it does not exist
20             --appdir location of application static files
21             --fallback_data_root location to fallback to if setting isn't found instead of
22             $HOME or $APPDIR\mhfs
23             -h|--help print this message
24             -v|--version print version
25             END_USAGE
26              
27             sub run {
28 0     0 0   binmode(STDOUT, ":utf8");
29 0           binmode(STDERR, ":utf8");
30              
31             # parse command line args into launchsettings
32 0           my %launchsettings;
33 0           my ($flush, $cfgdir, $fallback_data_root, $appdir, $help, $versionflag, $debug);
34 0 0         if(!GetOptions(
35             'flush' => \$flush,
36             'cfgdir=s' => \$cfgdir,
37             'fallback_data_root=s' => \$fallback_data_root,
38             'appdir=s' => \$appdir,
39             'help|h' =>\$help,
40             'version|v' => \$versionflag,
41             'debug|d' => \$debug,
42             )) {
43 0           print STDERR "$0: Invalid param\n";
44 0           print STDERR $USAGE;
45 0           exit(1);
46             }
47              
48 0 0         if($help) {
    0          
49 0           print $USAGE;
50 0           exit 0;
51             }
52             elsif($versionflag) {
53 0           print __PACKAGE__." $VERSION";
54 0           exit 0;
55             }
56 0           say __PACKAGE__ .": parsed command line args";
57              
58 0 0         $launchsettings{flush} = $flush if($flush);
59 0 0         $launchsettings{CFGDIR} = $cfgdir if($cfgdir);
60 0 0         $launchsettings{FALLBACK_DATA_ROOT} = $fallback_data_root if($fallback_data_root);
61 0 0         $launchsettings{APPDIR} = $appdir if($appdir);
62 0 0         $launchsettings{debug} = $debug if ($debug);
63              
64             # start the server (blocks)
65 0           say __PACKAGE__.": starting MHFS::HTTP::Server";
66 0           my $server = MHFS::HTTP::Server->new(\%launchsettings,
67             ['MHFS::Plugin::MusicLibrary',
68             'MHFS::Plugin::GetVideo',
69             'MHFS::Plugin::VideoLibrary',
70             'MHFS::Plugin::Youtube',
71             'MHFS::Plugin::BitTorrent::Tracker',
72             'MHFS::Plugin::OpenDirectory',
73             'MHFS::Plugin::Playlist',
74             'MHFS::Plugin::Kodi',
75             'MHFS::Plugin::BitTorrent::Client::Interface'],
76             );
77             }
78              
79             1;
80              
81             __END__