Chart-GRACE

 view release on metacpan or  search on metacpan

GRACE.pm  view on Meta::CPAN

returns the object.

=cut


sub new {

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

  my $xmgrace = {};

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

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

  # Store the current object - KLUDGE alert
  $Current = $xmgrace;

  # Launch the XMGR process

  if ($NPIPE) {

    # Increment counter
    $COUNTER++;

    # Create the named pipe if necessary
    # This is not really safe. Should be using File::Temp
    $xmgrace->{Npipe} = "/tmp/xmgrace_fifo$$" . "_$COUNTER";


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

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

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

    # Fork xmgr
    my $pid;
    if ($pid = fork) {
      # Parent
      # Open pipe
      $xmgrace->{Pipe} = new IO::File;
      $xmgrace->{Pipe}->open("> ". $xmgrace->npipe) or
	die "Can't open named pipe: $!";

    } elsif (defined $pid) {
      # Child
      exec 'xmgrace -noask -npipe '.$xmgrace->npipe . ' -timer 900';

    } else {
      die "Can't fork: $!\n";
    }
  } else {

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


  }

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

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


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

  return $xmgrace;
}


=item pipe

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

=cut

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

=item opt()

Return options object associated with XMGRACE object.

=cut

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

=item npipe()

Returns name of pipe associated with object.

=cut

sub npipe {
  my $self = shift;



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