PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|JUNOS|Methods.pm =

page 2 of 3



sub invoke_method
{
    my ($self, $fn, %args) = @_;
    my $bindings = $methods{ $fn };
    my $output = "";
    my $tag = "";
    my $attrs = "";
    trace("Methods", "$fn --> ", join("...", @_), "\n");

    foreach my $field (keys(%args)) {
	my $type = $bindings->{ $field };
	my $value = $args{ $field };

	($tag = $field) =~ s/_/-/g;

	if (ref($type) eq "TOGGLE" || ref($value) eq "TOGGLE") {
	    if ($value ne "0") {
		$output .= "    <$tag/>\n";
	    }

	} elsif (ref($value) eq "TOGGLE_NO") {
	    if ($value eq "0") {
		$output .= "    <no-$tag/>\n";
	    } else {
		$output .= "    <$tag/>\n";
	    }

	} elsif (ref($type) eq "STRING") {
	    $output .= "    <${tag}>${value}</${tag}>\n";

	} elsif ($type =~ /(\d)+\.\.(\d)+/) {
	    $output .= "    <${tag}>${value}</${tag}>\n";

	} elsif (ref($type) eq "DOM") {
	    $output .= $value->toString;
	    $output .= "\n";

	} elsif (ref($type) eq "ATTRIBUTE") {
	    $attrs .= " ${tag}=\"${value}\"\n";

	} elsif (ref($value)) {
	    $output .= $value->toString;
	    $output .= "\n";

	} else {
	    $output .= "    <${tag}>${value}</${tag}>\n";
	}
    }

    ($tag = $fn) =~ s/_/-/g;

    if ($output) {
	$output = "<rpc>\n  <${tag}${attrs}>\n${output}  </${tag}>\n</rpc>\n";
    } else {
	$output = "<rpc>\n  <${tag}${attrs}/>\n</rpc>\n";
    }

    $self->request($output);
}

sub AUTOLOAD
{
    my $name = substr($AUTOLOAD, rindex($AUTOLOAD, "::") + 2);
    unless ($methods{$name}) {
	Carp::croak("undefined function: $AUTOLOAD");
    }

    eval "sub $AUTOLOAD { invoke_method(shift, \"$name\", \@_); };";

#    *$AUTOLOAD = sub { invoke_method($name, @_); };
    goto &$AUTOLOAD;
}

##
# Load up methods via version
##
sub init
{
    my($version) = shift;
    my $current_dir;

    foreach my $dir (@INC) {
	if (-f "$dir/JUNOS/Methods.pm") {
	    $current_dir = $dir;
	    last;
	}
    }

    my $methods_dir = "$current_dir/JUNOS/$version";
    my @files = <$methods_dir/*_methods.pl>;

    for my $f (@files) {
        my $name = fileparse($f, '.pl');
        require $f;
	# use strict doesn't allow usage of bareword so have to
 	# use this block as a way around it.  Can't even hide
	# this inside init_methods because the init_methods
	# subroutine  doesn't see the hashtables in its scope.
	no strict 'refs';
        init_methods(%$name);
=2=

1| < PREV = PAGE 2 = NEXT > |3

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.0058291 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)