Chart-XMGR

 view release on metacpan or  search on metacpan

XMGR.pm  view on Meta::CPAN

returns the object.

=cut


sub new {

  my $proto = shift;
  my $class = ref($proto) || $proto;

  my $xmgr = {};
  
  $xmgr->{Pipe} = undef;    # File handle object of pipe  
  $xmgr->{Attached} = 0;    # Is an XMGR process attached
  $xmgr->{Set} = 0;         # Current set number
  $xmgr->{Graph} = 0;       # Current graph
  $xmgr->{Options}  = new PDL::Options( \%DEFAULTS );
  $xmgr->{Debug} = 0;       # Debugging flag
  $xmgr->{Npipe} = undef;   # Name of named pipe

  # Bless into class
  bless ($xmgr, $class);

  # Store the current object - KLUDGE alert
  $Current = $xmgr;
  
  # Launch the XMGR process
  
  if ($NPIPE) {

    # Increment counter
    $COUNTER++;

    # Create the named pipe if necessary
    $xmgr->{Npipe} = "/tmp/xmgr_fifo$$" . "_$COUNTER";


    # See if the pipe exists and or is not a pipe
    unless (-p $xmgr->npipe) {
      print "Making named pipe:".$xmgr->npipe ."..." if $xmgr->debug;
      unlink $xmgr->npipe;

      mkfifo($xmgr->npipe, 0600) || 
	croak "Couldnt create named pipe: $!"; # POSIX

      print "Done\n" if $xmgr->debug;
    }

    # Fork xmgr
    my $pid;
    if ($pid = fork) {
      # Parent
      # Open pipe
      $xmgr->{Pipe} = new IO::File;
      $xmgr->{Pipe}->open("> ". $xmgr->npipe) or
	die "Can't open named pipe: $!";
 
      
    } elsif (defined $pid) {
      # Child
      exec 'xmgr -noask -npipe '.$xmgr->npipe . ' -timer 900';
      
    } else {
      die "Can't fork: $!\n";
    }
  } else {

    # An anonymous pipe
    $xmgr->{Pipe} = new IO::Pipe;
    $xmgr->{Pipe}->writer('xmgr -pipe -noask');


  }

  $xmgr->{Pipe}->autoflush;
  $xmgr->{Attached} = 1;  

  # Configure the options
  $xmgr->{Options}->synonyms( \%SYNONYMS );
  $xmgr->{Options}->translation( \%TRANSLATION );


  # Set a default title
  $xmgr->prt('TITLE "Perl->XMGR"');

  return $xmgr;
  
  
}


=item pipe

Return file handle (of type IO::Pipe) associated with external XMGR process.

=cut

sub pipe {
  my $self = shift;
  if (@_) { $self->{Pipe} = shift;}
  return $self->{Pipe};
}

=item opt()

Return options object associated with XMGR object.

=cut

sub opt {
  my $self = shift;
  if (@_) { $self->{Options} = shift;}
  return $self->{Options};
}

=item npipe()

Returns name of pipe associated with object.

=cut



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