Chart-Graph

 view release on metacpan or  search on metacpan

Graph/Xmgrace/Base_Dataset_Option.pm  view on Meta::CPAN

    $self->_init(@_);
    return $self;
}

# 
# 
# Subroutine: _printline() 
# 
# Description: this function will print out a line that can be  
#              read with xmgrace (with the prepended @) 
# 
# 
# 
 
sub _printline ($$$$ ) { 
    my $self = shift;
    my ($handle, $string, $length) = @_;

    if (!$string) {
	print $handle "error: no string to print!\n";
	return 0;
    }

    print $handle "@";
    print $handle ' ' x $length;
    print $handle "$string"; 

    return 1;                   # just for fun 
} 

sub print($$$ ) {
    my $self = shift;
    my ($handle, $set) = @_;
    my $string = "";
  
    foreach $option (@{ $self->{"print_order"} }) {
	my $option_ref = $self->{"options"};

	if ($option eq "status" or $option eq "in_out_status") {   
	  
	    # we first check the status of the option, whether it's on/off
	    # if it's off, we don't print it out
	    if ($option_ref->{"status"} eq "off") {
		$string = "$set $self->{name} $option_ref->{$option}\n";
		$self->_printline($handle, $string, $self->{"length"});
		last;
	    }
	    $string = "$set $self->{name} $option_ref->{$option}\n";
	    $self->_printline($handle, $string, $self->{"length"});

	} else {	

	    # we skip hidden datasets
	    if ($option eq "hidden") {
		if ($option_ref->{"hidden"} eq "true") {
		    last;
		}
	    }

	    if (!ref($option_ref->{$option})) {
		if ($option eq "comment" or $option eq "legend") {
		    $string = "$set $option \"$option_ref->{$option}\"\n";	
		} elsif (!$self->{name}) {
		    $string = "$set $option $option_ref->{$option}\n";
		} else {
		    $string = "$set $self->{name} $option $option_ref->{$option}\n";
		}
		
	    } elsif (ref($option_ref->{$option}) eq ARRAY) {
		$substr = join (", ", (@{ $option_ref->{$option} })); 
		$string = "$set $self->{name} $option $substr\n";
	    } else { # a blessed object, use own print function (which in this case is the same)
		$option_ref->{$option}->print($handle, $set);
		next;
	    }

	    $self->_printline($handle, $string, $self->{"length"});
	    $string = "";
	}
    }
}

sub AUTOLOAD {
    my $self = shift;
    my $type = ref($self) || croak "$self is not an object";
    my $name = $AUTOLOAD;
    $name =~ s/.*://; #strip fully-qualified portion
    unless (($name eq "DESTROY") or (exists $self->{options}->{$name})) {
	croak "Can't access '$name' field in object of class $type";
    }

    if (@_) {
	return $self->{options}->{$name} = shift;
    } else {
	return $self->{options}->{$name};
    }
}

1;



( run in 0.582 second using v1.01-cache-2.11-cpan-39bf76dae61 )