Alien-XPA

 view release on metacpan or  search on metacpan

t/alien.t  view on Meta::CPAN

    # be firm if necessary
    if ( $xpamb_is_running && defined $child ) {

        diag( 'force remove our xpamb' );

        retry {

            if ( $^O eq 'MSWin32' ) {
                use subs qw( Win32::Process::STILL_ACTIVE );
                $child->GetExitCode( my $exitcode );
                $child->Kill( 0 ) if $exitcode == Win32::Process::STILL_ACTIVE;
            }

            else {
                $child->kill( 9 ) unless $child->is_complete;
            }

            if ( run( 'xpaaccess', 'XPAMB:*' )->out !~ 'yes' ) {
                $xpamb_is_running = 0;
                return;
            }

            die;
        };
    }

    bail_out( 'unable to remove xpamb' )
      if $xpamb_is_running;
}

{
    package MyRun;
    use Capture::Tiny qw( capture );

    sub new {
        my ( $class, @args ) = @_;
        my ( $out, $err, $exit ) = capture { system { $args[0] } @args; $?; };

        my $signal = $exit & 127;
        my $core   = $exit & 128;
        $exit = $exit >> 8;

        return bless {
            cmd    => \@args,
            out    => $out,
            err    => $err,
            exit   => $exit,
            signal => $signal,
            $core  => $core,
        }, $class;
    }

    sub out    { $_[0]->{out} }
    sub err    { $_[0]->{err} }
    sub exit   { $_[0]->{exit} }                  ## no critic (Subroutines::ProhibitBuiltinHomonyms)
    sub core   { $_[0]->{core} }
    sub signal { $_[0]->{signal} }
    sub cmd    { join q{ }, @{ $_[0]->{cmd} } }

    sub stringify {
        sprintf "cmd: %s\nexit: %d\ncore; %s\nsignal: %s\nstdout: %s\nstderr: %s\n",
          $_[0]->cmd,
          $_[0]->exit,
          $_[0]->core,
          $_[0]->signal,
          $_[0]->out,
          $_[0]->err;
    }
}

END {
    remove_xpamb();
}

__DATA__

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <xpa.h>

int
connected(const char *class)
{
    char *names[1];
    char *messages[1];

    int found =
      XPAAccess( NULL,
                 "XPAMB:*",
                 NULL,
                 "g",
                 names,
                 messages,
                 1 );

    if ( found && names[0] && strcmp( names[0], "XPAMB:xpamb" ) ) found = 1;
    else found = 0;

    if ( names[0] ) free( names[0] );
    if ( messages[0] ) free( messages[0] );

    return found;
}

const char * version( const char* class ) {
    const char* version = XPA_VERSION;
    return version;
}

MODULE = TA_MODULE PACKAGE = TA_MODULE

int connected(class);
    const char *class;

const char* version(class);
    const char *class;



( run in 0.749 second using v1.01-cache-2.11-cpan-e1769b4cff6 )