While I've been programming in Perl forever it seems, I do very, very little OOP in Perl so I'm a bit confused by this code I was shown recently. I'm hoping you folks might be able to divine why it would be done this way and finally, why the issue I'm seeing is occurring.

Firstly, there are two modules named AuditLogReview_Event.pm and AuditLogReview_Event08.pm. This is the first:
use strict; use warnings; package Event; sub new { my ($class) = @_; my $self = {}; $self = { 'Event Type' => 'Windows 2003', }; bless $self, ref($class) || $class; return $self; } package Security; our @ISA = qw (Event); @PARENT::ISA = @ISA; sub new { my $class = shift; my($self) = $class->PARENT::new(@_); $self->{'EventLog'} = 'Security'; return (bless($self, $class)); + # return object } 1;
My first question is: what's the purpose of
@ISA = qw(Event); @PARENT::ISA = @ISA
? To me, that seems that it would make each class a subclass of the other. Why do that?

For my second issue I need to show you the rest of the code, AuditLogReview_Event08.pm:

use strict; use warnings; package Event08; sub new { my ($class) = @_; my $self = {}; $self = { 'Event Type' => 'Windows 2008', }; bless $self, ref($class) || $class; return $self; } package Security08; our @ISA = qw (Event08); @PARENT::ISA = @ISA; sub new { my $class = shift; my($self) = $class->PARENT::new(@_); $self->{'EventLog'} = 'Security'; return (bless($self, $class)); + # return object } 1;

And finally, the test script, AuditTest.pl:

#!/usr/bin/perl -w use strict; use warnings; use AuditLogReview_Event; # handles 2003 events use AuditLogReview_Event08; # handles 2008 events EventWindowsHandler('.evt'); EventWindowsHandler('.evtx'); sub EventWindowsHandler { my $oEvent; my $ext = shift; if ($ext eq '.evt') { $oEvent = Security->new(); } elsif ( $ext eq '.evtx') { $oEvent = Security08->new(); # can I call Security from the + AuditLogReview_Event08 file? } print "Processing $oEvent->{'Event Type'} $oEvent->{'EventLog'} ev +ent.\n"; }

Now, the thing is, as written when it runs it produces the following:

C:\Users\A209624\Desktop>perl AuditTest.pl
Processing Windows 2008 Security event.
Processing Windows 2008 Security event.

Putting some debugging in there, I see that the Security->new() call goes to the right place, but when it does it's

$class->PARENT::new(@_)
it's hitting Event08 instead of Event. Why?

I was able to get the behavior I wanted by changing the my $self = $class->PARENT::new(@_) in each package to

my $self = Event->new(@_); my $self = Event08->new(@_);

But I'm still unsure why the first way didn't work correctly.

Thanks!

mr.nick ...


In reply to Can you help me understand this OO notation/issue? by mr.nick

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.