Hello Monks,

I am having a problem with loading multiple plugins using module pluggable. It seems like the second plugin is overwriting the first plugin... Can anyone help me shed some light on what is going on here?
Thanks!

To Illustrate my issue, here is the output from my program. As you can see the name has been overwritten in after the "In Atest" heading

[root@elara object_problem]# perl snmp_monitor.pl starting snmp_monitor.pl Found Plugins: Plugin: SNMPMonitor::Plugin::Atest Plugin: SNMPMonitor::Plugin::Btest --> Plugins Dump: $VAR1 = 'SNMPMonitor::Plugin::Atest'; $VAR2 = 'SNMPMonitor::Plugin::Btest'; --> Objects Dump: $VAR1 = bless( { 'plugin_oid' => '0.0.0', 'name' => 'Atest', 'root_oid' => '.1.3.6.1.4.1.99999.', 'full_name' => 'SNMPMonitor::Plugin::Atest', 'full_oid' => '.1.3.6.1.4.1.99999.0.0.0' }, 'SNMPMonitor::Plugin::Atest' ); $VAR2 = bless( { 'plugin_oid' => '1.1.1', 'name' => 'Btest', 'root_oid' => '.1.3.6.1.4.1.99999.', 'full_name' => 'SNMPMonitor::Plugin::Btest', 'full_oid' => '.1.3.6.1.4.1.99999.1.1.1' }, 'SNMPMonitor::Plugin::Btest' ); In Atest Print Test: 0Full Name: SNMPMonitor::Plugin::Btest Name: Btest OID: 1.1.1 Root OID: .1.3.6.1.4.1.99999. Full OID: .1.3.6.1.4.1.99999.1.1.1 In Btest Print Test: 0Full Name: SNMPMonitor::Plugin::Btest Name: Btest OID: 1.1.1 Root OID: .1.3.6.1.4.1.99999. Full OID: .1.3.6.1.4.1.99999.1.1.1

Here is the associated code:

Listing: snmp_monitor.pl
#!/usr/bin/perl use Data::Dumper; use strict; use warnings; use common::sense; use lib '/root/snmp_monitor/trunk'; use SNMPMonitor; use SNMPMonitor::Plugin; BEGIN { print STDERR "starting $0\n"; } # Private vars my $root_oid = '.1.3.6.1.4.1.99999.'; my $monitor = SNMPMonitor->new; my @plugins = $monitor->plugins(); #print "Found Plugins: \n" . Dumper @plugins; print STDERR "\nFound Plugins: \n"; print STDERR "Plugin: $_ \n" foreach @plugins; print STDERR "\n"; my @objects; push @objects, $_->new($root_oid) foreach @plugins; print STDERR "\n\n--> Plugins Dump:\n" . Dumper @plugins; print STDERR "\n\n--> Objects Dump:\n" . Dumper @objects; foreach my $obj (@objects) { print STDERR "Print Test; \n" . $obj->print_test; print STDERR "Full Name: " . $obj->full_name . "\n"; print STDERR "Name: " . $obj->name . "\n"; print STDERR "OID: " . $obj->plugin_oid . "\n"; print STDERR "Root OID: " . $obj->root_oid . "\n"; print STDERR "Full OID: " . $obj->full_oid . "\n\n"; }
listing SNMPMonitor.pm
package SNMPMonitor; use Module::Pluggable require => 1; sub new { my $class = shift; my $self = {}; bless $self, $class; } sub evaluate_plugin { } 1; __END__
listing SNMPMonitor/Plugin.pm
package SNMPMonitor::Plugin; use common::sense; #use NetSNMP::ASN (':all'); sub new { my $obj_class = shift; my $root_oid = shift; my $class = ref $obj_class || $obj_class; my ($name) = $class =~ /::Plugin::(.*)/; my $self = { name => $name, full_name => $class, root_oid => $root_oid, plugin_oid => '', full_oid => '', }; bless $self, $class; # create accessor methods for defined parameters for my $datum (keys %{$self}) { no strict "refs"; *$datum = sub { shift; # XXX: ignore calling class/object $self->{$datum} = shift if @_; return $self->{$datum}; }; } $self->set_oid(); return $self; } # Set the OID using plugin defined OID. sub set_oid { my $self = shift; $self->plugin_oid($self->set_plugin_oid); $self->full_oid($self->root_oid . $self->plugin_oid); } 1; __END__
listing: SNMPMonitor/Plugin/Atest.pm
package SNMPMonitor::Plugin::Atest; use strict; use warnings; #use common::sense; use NetSNMP::ASN (':all'); # use Smart::Comments; my @ISA = qw(SNMPMonitor::Plugin); sub set_plugin_oid {'0.0.0'}; sub monitor { use Data::Dumper; print STDERR "--> In Object \nDumper: " . Dumper @_; my $class = shift; my ($handler, $registration_info, $request_info, $requests) = @_; my $request; my $this_request = $requests->next(); $requests->setValue(ASN_OCTET_STR, "Test Successful"); } sub print_test { my $self = shift; print STDERR "In " . $self->full_name . "\n"; } 1; __END__
for completeness, here is BTest, however, the only difference is the OID.
listing: SNMPMonitor/Plugin/Btest.pm
package SNMPMonitor::Plugin::Btest; use strict; use warnings; #use common::sense; use NetSNMP::ASN (':all'); # use Smart::Comments; my @ISA = qw(SNMPMonitor::Plugin); sub set_plugin_oid {'1.1.1'}; sub monitor { use Data::Dumper; print STDERR "--> In Object \nDumper: " . Dumper @_; my $class = shift; my ($handler, $registration_info, $request_info, $requests) = @_; my $request; # do { # print STDERR "refs: ",join(", ", ref($handler), ref($registra +tion_info), # ref($request_info), ref($requests)),"\n"; # print STDERR "processing a request of type " . $request_info- +>getMode() . "\n"; # }; my $this_request = $requests->next(); $requests->setValue(ASN_OCTET_STR, "BTest Successful"); } sub print_test { my $self = shift; print STDERR "In " . $self->{'name'} . "\n"; my $a = 0; ### @_; } 1; __END__

When built in the above structure I receive the posted output, when BTest.pm is named to BTest.pm.old the ATest object works correctly.


In reply to Problem with Inheriting a Super Class by PyrexKidd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.