App-MHFS

 view release on metacpan or  search on metacpan

lib/App/MHFS.pm  view on Meta::CPAN


    MHFS::Util->import();

    sub new {
        my ($class, $launchsettings, $plugins, $routes) = @_;

        $SIG{PIPE} = sub {
            print STDERR "SIGPIPE @_\n";
        };

        binmode(STDOUT, ":utf8");
        binmode(STDERR, ":utf8");

        # load settings
        say __PACKAGE__.": loading settings";
        my $settings = MHFS::Settings::load($launchsettings);
        if((exists $settings->{'flush'}) && ($settings->{'flush'})) {
            say __PACKAGE__.": setting autoflush on STDOUT and STDERR";
            STDOUT->autoflush(1);
            STDERR->autoflush(1);
        }

lib/App/MHFS.pm  view on Meta::CPAN

        # open the file and get the size
        my %fileitem = ('requestfile' => $requestfile);
        my $currentsize;
        if($self->{'method'} ne 'HEAD') {
            my $FH;
            if(! open($FH, "<", $requestfile)) {
                say "SLF: open failed";
                $self->Send404;
                return;
            }
            binmode($FH);
            my $st = stat($FH);
            if(! $st) {
                $self->Send404();
                return;
            }
            $currentsize = $st->size;
            $fileitem{'fh'} = $FH;
        }
        else {
            $currentsize = (-s $requestfile);

lib/App/MHFS.pm  view on Meta::CPAN

    }

    # currently only supports fixed filelength
    sub SendPipe {
        my ($self, $FH, $filename, $filelength, $mime) = @_;
        if(! defined $filelength) {
            $self->Send404();
        }

        $mime //= getMIME($filename);
        binmode($FH);
        my %fileitem;
        $fileitem{'fh'} = $FH;
        $fileitem{'get_current_length'} = sub {
            my $tocheck = defined $self->{'header'}{'_RangeEnd'} ? $self->{'header'}{'_RangeEnd'}+1 : $filelength;
            return min($filelength, $tocheck);
        };

        $self->_SendDataItem(\%fileitem, {
           'size'     => $filelength,
           'mime'     => $mime,

lib/App/MHFS.pm  view on Meta::CPAN

        my ($mpa, $prochandlers, $handlesettings) = @_;

        my %self = ('time' => clock_gettime(CLOCK_MONOTONIC), 'evp' => $mpa->{'evp'});
        # inreader/inwriter   is the parent to child data channel
        # outreader/outwriter is the child to parent data channel
        # errreader/errwriter is the child to parent log channel
        pipe(my $inreader, my $inwriter)   or die("pipe failed $!");
        pipe(my $outreader, my $outwriter) or die("pipe failed $!");
        pipe(my $errreader, my $errwriter) or die("pipe failed $!");
        # the childs stderr will be UTF-8 text
        binmode($errreader, ':encoding(UTF-8)');
        my $pid = fork() // do {
            say "failed to fork";
            return undef;
        };
        if($pid == 0) {
            close($inwriter);
            close($outreader);
            close($errreader);
            open(STDIN,  "<&", $inreader) or die("Can't dup \$inreader to STDIN");
            open(STDOUT, ">&", $errwriter) or die("Can't dup \$errwriter to STDOUT");

lib/App/MHFS.pm  view on Meta::CPAN

--cfgdir              location of configuration directory, will be created if
  it does not exist
--appdir              location of application static files
--fallback_data_root  location to fallback to if setting isn't found instead of
  $HOME or $APPDIR\mhfs
-h|--help             print this message
-v|--version          print version
END_USAGE

sub run {
    binmode(STDOUT, ":utf8");
    binmode(STDERR, ":utf8");

    # parse command line args into launchsettings
    my %launchsettings;
    my ($flush, $cfgdir, $fallback_data_root, $appdir, $help, $versionflag);
    if(!GetOptions(
        'flush' => \$flush,
        'cfgdir=s' => \$cfgdir,
        'fallback_data_root=s' => \$fallback_data_root,
        'appdir=s' => \$appdir,
        '--help|h' =>\$help,



( run in 0.232 second using v1.01-cache-2.11-cpan-2b0bae70ee8 )