Professional Web Applications Themes

Module Object and sub module function - PERL Beginners

Howdy folks, Yet another module question. I'm so close and I've done this but I can't get it to work. I am writing a module that is an extension/sub module of an existing module. use ... MyNewxySubModule qw(function); $obj = new->Original::Package(); for(Original::Package::MyNewxySubModule::functi on($obj,$arg)) { .... This works like a charm but what I'd really like to do is this: Use lib '/home/me/modules/'; use MyNewxySubModule qw(function); # package Original::Package::MyNewxySubModule; $obj = new->Original::Package(); for($obj->function($arg)) { .... When I try that it says: Original::Package=GLOB(0x829da00) is an [unexpected] object, aborting at ./ModTest.pl line 21 Line 21 is my for($obj->.... Any ideas what I'm missing ...

  1. #1

    Default Module Object and sub module function

    Howdy folks,

    Yet another module question.

    I'm so close and I've done this but I can't get it to work.

    I am writing a module that is an extension/sub module of an existing module.

    use ... MyNewxySubModule qw(function);

    $obj = new->Original::Package();
    for(Original::Package::MyNewxySubModule::functi on($obj,$arg)) { ....


    This works like a charm but what I'd really like to do is this:

    Use lib '/home/me/modules/';
    use MyNewxySubModule qw(function); # package Original::Package::MyNewxySubModule;

    $obj = new->Original::Package();
    for($obj->function($arg)) { ....

    When I try that it says:
    Original::Package=GLOB(0x829da00) is an [unexpected] object, aborting at ./ModTest.pl line 21
    Line 21 is my for($obj->....

    Any ideas what I'm missing ??

    TIA

    Dan
    Dan Muey Guest

  2. #2

    Default RE: Module Object and sub module function

    I guess by extension you mean that you are trying to subclass a module. In that case you would need to inherit from that parent class with something like:

    our ISA = qw(ParentClass)

    or

    use base qw(ParentClass)

    Then you can call the methods of the parent class on the instances of this subclass.

    -Sharad
    > -----Original Message-----
    > From: Dan Muey [mailto:dmueyinfiniplex.com]
    > Sent: Wednesday, October 29, 2003 9:56 AM
    > To: [email]beginnersperl.org[/email]
    > Subject: Module Object and sub module function
    >
    >
    > Howdy folks,
    >
    > Yet another module question.
    >
    > I'm so close and I've done this but I can't get it to work.
    >
    > I am writing a module that is an extension/sub module of an
    > existing module.
    >
    > use ... MyNewxySubModule qw(function);
    >
    > $obj = new->Original::Package();
    > for(Original::Package::MyNewxySubModule::functi on($obj,$arg
    > )) { ....
    >
    >
    > This works like a charm but what I'd really like to do is this:
    >
    > Use lib '/home/me/modules/';
    > use MyNewxySubModule qw(function); # package
    > Original::Package::MyNewxySubModule;
    >
    > $obj = new->Original::Package();
    > for($obj->function($arg)) { ....
    >
    > When I try that it says:
    > Original::Package=GLOB(0x829da00) is an [unexpected] object,
    > aborting at ./ModTest.pl line 21
    > Line 21 is my for($obj->....
    >
    > Any ideas what I'm missing ??
    >
    > TIA
    >
    > Dan
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    > For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    >
    >
    Sharad Gupta Guest

  3. #3

    Default RE: Module Object and sub module function

    > I guess by extension you mean that you are trying to subclass
    > a module. In that case you would need to inherit from that
    Yeah I guess that is the term.
    > parent class with something like:
    >
    > our ISA = qw(ParentClass)
    >
    > or
    >
    > use base qw(ParentClass)
    >
    > Then you can call the methods of the parent class on the
    > instances of this subclass.
    Thanks Sharad for the info.

    That didn't work, but changing my package like so :

    sub function {}
    To
    sub ParentClass::function {}

    Worked perfect.

    The problem is now:

    Is it kosher to mess with the ParentClass's name space like
    that (only if imported by the script of course) or is that
    the only to acomplish that?

    (short of creating a ParentName::MyModule object, which
    seems like just an extra step in this case or doing the
    ParentName::MyModule::function($obj,$arg) method or
    function($obj,$arg) if imported in use statement)

    Basically I use the ParentName's $obj inside my functions
    and they are expecting it as the first arg.

    $obj->MyModule::function($arg); would be the coolest way
    (leaving my functions as sub function instead of sub
    NameSpace::Evil::function)

    Is this possible or am I just batty!?

    TIA

    Dan
    >
    > -Sharad
    >
    > > -----Original Message-----
    > > From: Dan Muey [mailto:dmueyinfiniplex.com]
    > > Sent: Wednesday, October 29, 2003 9:56 AM
    > > To: [email]beginnersperl.org[/email]
    > > Subject: Module Object and sub module function
    > >
    > >
    > > Howdy folks,
    > >
    > > Yet another module question.
    > >
    > > I'm so close and I've done this but I can't get it to work.
    > >
    > > I am writing a module that is an extension/sub module of an
    > > existing module.
    > >
    > > use ... MyNewxySubModule qw(function);
    > >
    > > $obj = new->Original::Package();
    > > for(Original::Package::MyNewxySubModule::functi on($obj,$arg
    > > )) { ....
    > >
    > >
    > > This works like a charm but what I'd really like to do is this:
    > >
    > > Use lib '/home/me/modules/';
    > > use MyNewxySubModule qw(function); # package
    > > Original::Package::MyNewxySubModule;
    > >
    > > $obj = new->Original::Package();
    > > for($obj->function($arg)) { ....
    > >
    > > When I try that it says:
    > > Original::Package=GLOB(0x829da00) is an [unexpected] object,
    > > aborting at ./ModTest.pl line 21
    > > Line 21 is my for($obj->....
    > >
    > > Any ideas what I'm missing ??
    > >
    > > TIA
    > >
    > > Dan
    > >
    > > --
    > > To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    > > For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    > >
    > >
    >
    Dan Muey Guest

  4. #4

    Default Re: Module Object and sub module function

    Hi Dan.

    There's a few things wrong here, and I'm struggling to work out what you're
    trying to do.

    Dan Muey wrote:
    >
    > Yet another module question.
    >
    > I'm so close and I've done this but I can't get it to work.
    >
    > I am writing a module that is an extension/sub module of an existing module.
    >
    > use ... MyNewxySubModule qw(function);
    We really need to see what's inside MyNewxySubModule.pm. If you're
    subclassing Original::Package then it should look something like:

    package MyNewxySubModule;

    require Original::Package;
    our ISA = qw(Original::Package);

    is that about right?
    > $obj = new->Original::Package();
    So then what's this? It looks like you're trying to call the constructor
    of the Original::Package class, but it compiles as

    $obj = 'new'->Original::Package;

    which I can't even understand to be valid syntax unless you've also got
    a subroutine called 'Package' in package 'Original' :-/

    my $obj = new Original::Package;
    or
    my $obj = Original::Package->new;

    but even then you're creating an instance of your base class, not your
    new subclass.
    > for(Original::Package::MyNewxySubModule::functi on($obj,$arg)) { ....
    Here's yet another new package name which you haven't mentioned. What's
    Original::Package::MyNewxySubModule? You also seem to be calling it
    with your Original::Package object as its first parameter as if you were
    trying to emulate the object method call $obj->function but using a
    different class.
    > This works like a charm but what I'd really like to do is this:
    I'm very surprised, but...
    > Use lib '/home/me/modules/';
    > use MyNewxySubModule qw(function); # package Original::Package::MyNewxySubModule;
    From this comment it looks like your MyNewxySubModule.pm file might look
    like

    package Original::Package::MyNewxySubModule;

    require Original::Package;
    our ISA = qw(Original::Package);

    The name of the module should always be the same as the class name.
    > $obj = new->Original::Package();
    > for($obj->function($arg)) { ....
    I'm still struggling to see why you're not using your new subclass at all. But
    assuming Original::Package::new exists and returns a blessed reference, and
    Original::Package::function exists then this should all be OK.
    > When I try that it says:
    > Original::Package=GLOB(0x829da00) is an [unexpected] object, aborting at ./ModTest.pl line 21
    > Line 21 is my for($obj->....
    I haven't the faintest idea what that error message might mean. But it looks like you're
    way off beam :)
    > Any ideas what I'm missing ??
    You've missed showing us where you've ed up!

    Cheers,

    Rob


    Rob Dixon Guest

  5. #5

    Default Re: Module Object and sub module function


    > Hi Dan.
    >
    > There's a few things wrong here, and I'm struggling to work out what
    you're
    > trying to do.
    >
    > Dan Muey wrote:
    > >
    > > Yet another module question.
    > >
    > > I'm so close and I've done this but I can't get it to work.
    > >
    > > I am writing a module that is an extension/sub module of an existing
    module.
    > >
    > > use ... MyNewxySubModule qw(function);
    >
    > We really need to see what's inside MyNewxySubModule.pm. If you're
    > subclassing Original::Package then it should look something like:
    >
    > package MyNewxySubModule;
    >
    > require Original::Package;
    > our ISA = qw(Original::Package);
    >
    > is that about right?
    >
    > > $obj = new->Original::Package();
    >
    > So then what's this? It looks like you're trying to call the constructor
    > of the Original::Package class, but it compiles as
    >
    > $obj = 'new'->Original::Package;
    >
    > which I can't even understand to be valid syntax unless you've also got
    > a subroutine called 'Package' in package 'Original' :-/
    >
    > my $obj = new Original::Package;
    > or
    > my $obj = Original::Package->new;
    >
    > but even then you're creating an instance of your base class, not your
    > new subclass.
    >
    > > for(Original::Package::MyNewxySubModule::functi on($obj,$arg)) { ....
    >
    > Here's yet another new package name which you haven't mentioned. What's
    > Original::Package::MyNewxySubModule? You also seem to be calling it
    > with your Original::Package object as its first parameter as if you were
    > trying to emulate the object method call $obj->function but using a
    > different class.
    >
    > > This works like a charm but what I'd really like to do is this:
    >
    > I'm very surprised, but...
    >
    > > Use lib '/home/me/modules/';
    > > use MyNewxySubModule qw(function); # package
    Original::Package::MyNewxySubModule;
    >
    > >From this comment it looks like your MyNewxySubModule.pm file
    might look
    > like
    >
    > package Original::Package::MyNewxySubModule;
    >
    > require Original::Package;
    > our ISA = qw(Original::Package);
    >
    > The name of the module should always be the same as the class name.
    >
    > > $obj = new->Original::Package();
    > > for($obj->function($arg)) { ....
    >
    > I'm still struggling to see why you're not using your new subclass at
    all. But
    > assuming Original::Package::new exists and returns a blessed
    reference, and
    > Original::Package::function exists then this should all be OK.
    >
    > > When I try that it says:
    > > Original::Package=GLOB(0x829da00) is an [unexpected] object,
    aborting at ./ModTest.pl line 21
    > > Line 21 is my for($obj->....
    >
    > I haven't the faintest idea what that error message might mean. But it
    looks like you're
    > way off beam :)
    >
    > > Any ideas what I'm missing ??
    >
    > You've missed showing us where you've ed up!
    >
    > Cheers,
    >
    Thank god Rob wrote this, I thought I had been asleep for about 6 months
    and there was a whole new way to access into a symbol table looking for
    a class constructor!! Just throwing in my two cents that I was as
    confused as Rob :-)....

    The beginners list just wouldn't be pushed to the edge without you Dan! ;-)

    [url]http://danconia.org[/url]

    Wiggins D Anconia Guest

  6. Moderated Post

    Default RE: Module Object and sub module function

    Removed by Administrator
    Dan Muey Guest
    Moderated Post

  7. #7

    Default RE: Module Object and sub module function

    Sorry for the confusion, I was switching example names on everyone.

    I think I've got it.

    I've made it object oriented and functional based. (Gulp, kinda scary :-))

    I have

    package Parent::Module::MyModule;

    With simply bare function names like so:
    (IE not Parent::Module::functionname {} so as not to invad namespace) sub funtionname {}

    So One can do this:

    use Parent::Module::MyModule;
    my $r = Parent::Module::MyModule::functionname($parentobj, $arg);

    use Parent::Module::MyModule; qw(functionname);
    my $r = functionname($parentobj,$arg);

    Or if new() is called each function is "smart" enough to know that the first
    thing is a $self object and not the parent $obj and to use $self->{Parent}
    for the parent $obj.

    use Parent::Module::MyModule;
    my $newobj = new Parent::Module::MyModule($parentobj);
    my $r = $newobj->functionname($arg);

    Does that seem about right?

    Sorry for the confusion but it's been a fun learning example for me,
    sorry if I made it Monday for you :)

    Dan
    Dan Muey Guest

  8. #8

    Default RE: Module Object and sub module function

    Maybe OT. But just curious. What do the experts say about exporting function from OO modules??.
    Everytime i need something like this, i end up making those functions as Class methods.

    -Sharad
    > -----Original Message-----
    > From: Dan Muey [mailto:dmueyinfiniplex.com]
    > Sent: Wednesday, October 29, 2003 3:34 PM
    > To: [email]beginnersperl.org[/email]
    > Subject: RE: Module Object and sub module function
    >
    >
    > Sorry for the confusion, I was switching example names on everyone.
    >
    > I think I've got it.
    >
    > I've made it object oriented and functional based. (Gulp,
    > kinda scary :-))
    >
    > I have
    >
    > package Parent::Module::MyModule;
    >
    > With simply bare function names like so:
    > (IE not Parent::Module::functionname {} so as not to invad
    > namespace) sub funtionname {}
    >
    > So One can do this:
    >
    > use Parent::Module::MyModule;
    > my $r = Parent::Module::MyModule::functionname($parentobj, $arg);
    >
    > use Parent::Module::MyModule; qw(functionname);
    > my $r = functionname($parentobj,$arg);
    >
    > Or if new() is called each function is "smart" enough to know
    > that the first
    > thing is a $self object and not the parent $obj and to use
    > $self->{Parent}
    > for the parent $obj.
    >
    > use Parent::Module::MyModule;
    > my $newobj = new Parent::Module::MyModule($parentobj);
    > my $r = $newobj->functionname($arg);
    >
    > Does that seem about right?
    >
    > Sorry for the confusion but it's been a fun learning example for me,
    > sorry if I made it Monday for you :)
    >
    > Dan
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    > For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    >
    >
    Sharad Gupta Guest

  9. #9

    Default RE: Module Object and sub module function

    Hi Dan,

    In article
    <D6D77DB239A2004BB08A240E2E71460D12BF57LSLOFFICE. infiniplex.infiniplex.com>,
    Dan Muey wrote:
    > Sorry for the confusion, I was switching example names on everyone.
    >
    > I think I've got it.
    >
    > I've made it object oriented and functional based. (Gulp, kinda scary :-))
    >
    > I have
    >
    > package Parent::Module::MyModule;
    You may not need it anymore, but for anyone else, I found the "Learning
    Objects, References & Modules" book to be really helpful with all this.


    -K

    --
    Kevin Pfeiffer

    Kevin Pfeiffer Guest

  10. #10

    Default Re: Module Object and sub module function

    Dan Muey wrote:
    >
    > Sorry for the confusion, I was switching example names on everyone.
    >
    > I think I've got it.
    >
    > I've made it object oriented and functional based. (Gulp, kinda scary :-))
    >
    > I have
    This is in your Mymodule.pm presumably?
    > package Parent::Module::MyModule;
    My only proviso is that in your first post you were using

    use lib '/home/me/modules/';
    use use Parent::Module::MyModule;

    in which case your module source should be in

    /home/me/modules/Parent/Module/MyModule.pm
    > With simply bare function names like so:
    > (IE not Parent::Module::functionname {} so as not to invad namespace) sub funtionname {}
    That's exactly the way subclassing should work: remember that the only
    access you're supposed to have to a class is through its public
    interface. Perl makes it very easy to break rules like this.
    > So One can do this:
    >
    > use Parent::Module::MyModule;
    > my $r = Parent::Module::MyModule::functionname($parentobj, $arg);
    >
    > use Parent::Module::MyModule; qw(functionname);
    > my $r = functionname($parentobj,$arg);

    Neither of these is the right way to go about things. The first tries to cheat
    by pretending to the method function that it's being called as a standard Perl
    method call $parentobj->functionname. If you don't want to use it that way it
    shouldn't be a method at all.

    The second isn't right either. That qw(functionname) is sitting on its own
    without making any difference to the world around it. If you had 'use warnings'
    it would have told you so. Also you're exporting a method function and calling
    it the same way as before.

    I'm worried about what your $parentobj is. From its name I would think it's
    a Parent::Module object, but your then trying to call a method from your new
    subclass on it.
    > Or if new() is called each function is "smart" enough to know that the first
    > thing is a $self object and not the parent $obj and to use $self->{Parent}
    > for the parent $obj.
    This doesn't make sense. There should be no 'parent' object, just an object.
    There is a parent (base) class and a subclass and all objects should belong
    to one or the other. The existence of a $self->{Parent} implies that the
    objects can be tree-structured, but this is part of the coding of the module
    and nothing to do with class hierarchy.
    > use Parent::Module::MyModule;
    > my $newobj = new Parent::Module::MyModule($parentobj);
    > my $r = $newobj->functionname($arg);
    >
    > Does that seem about right?
    Well yes, it does look about right. But I can't see how you got here from
    what's gone before! It still looks like you think you need to pass a
    'parent' object to the subclass constructor to create your $newobj. Unless,
    like I say, you're creating a fancy object that links to others of the same
    type.
    > Sorry for the confusion but it's been a fun learning example for me,
    > sorry if I made it Monday for you :)
    It's always Christmas Day for me Dan!

    But I think you need to show us your code. I'm sure you're making things
    too hard for yourself. Post it off-group to me if you'd rather and I'll
    mark it up.

    Cheers,

    Rob


    Rob Dixon Guest

  11. #11

    Default Re: Module Object and sub module function

    Dan Muey wrote:
    > Howdy folks,
    >
    > Yet another module question.
    >
    > I'm so close and I've done this but I can't get it to work.
    >
    > I am writing a module that is an extension/sub module of an existing module.
    >
    > use ... MyNewxySubModule qw(function);
    >
    > $obj = new->Original::Package();
    > for(Original::Package::MyNewxySubModule::functi on($obj,$arg)) { ....
    >
    > This works like a charm but what I'd really like to do is this:
    >
    > Use lib '/home/me/modules/';
    > use MyNewxySubModule qw(function); # package Original::Package::MyNewxySubModule;
    >
    > $obj = new->Original::Package();
    > for($obj->function($arg)) { ....
    >
    > When I try that it says:
    > Original::Package=GLOB(0x829da00) is an [unexpected] object, aborting at ./ModTest.pl line 21
    > Line 21 is my for($obj->....
    >
    > Any ideas what I'm missing ??
    Hi Dan,

    It sounds like you have a concept of the purpose of inheritance, but some of it backward, and
    some of that magic is irrelevant to Perl, since Perl lacks types. The ISA relationship means
    that you can store objects of various subtypes in a cntainer declared for their supertype, for
    instance. Doesn't matter much in Perl, since containers can hold scalars of any type anyway.

    The other advantage of inheritance, and a very relevant one, is the ability to access *methods of
    base types* through anobject declared as a subtype. The important point is that ISA [pronounced
    always "izza'"] izza one-way relationship in most cases. Anytime you slip behind the wheel of a
    Lamborghini, you are getting into an automobile. Don't you just wish the converse were true?
    No, you can't buy a Pinto and do 165 mph down Main St. That method simply isn't available in an
    object of the generic Automobile class.

    Joseph


    R. Joseph Newton Guest

  12. #12

    Default Re: Module Object and sub module function

    Dan Muey wrote:
    >
    >
    > Basically I use the ParentName's $obj inside my functions
    > and they are expecting it as the first arg.
    >
    > $obj->MyModule::function($arg); would be the coolest way
    > (leaving my functions as sub function instead of sub
    > NameSpace::Evil::function)
    >
    > Is this possible or am I just batty!?
    >
    Absolutely on the mark! Bravo!

    Then catch it in the function with:
    my $self = shift;

    What is left of the parameter list after shifting out the object
    reference is the parameter list as appears inside the parentheses of
    the call to the function:

    $my_object->my_sub($whats_this, $who_knows, $why_bother);

    sub my_sub {
    my $self = shift;
    my ($whats_this, $who_knows, $why_bother) = _
    ... #do stuff with $whats_this, $who_knows, and $why_bother
    }

    It makes for great typographic convenience, too, when you are
    prototyping/testing your objects.

    Joseph

    R. Joseph Newton Guest

  13. #13

    Default Re: Module Object and sub module function

    "Gupta, Sharad" wrote:
    > Maybe OT. But just curious. What do the experts say about exporting function from OO modules??.
    > Everytime i need something like this, i end up making those functions as Class methods.
    >
    > -Sharad
    In most cases, you should. Access through an object provides context and, IMHO much needed,
    grounding for a function. I took this up in an earlier thread more specific to the topic, and you
    may profit by starting a new original thread.

    In brief, if you want to be able to access a package function directly, you have to have it in the
    EXPORT array of the package, or in the EXPORT_OK and call it specifically:

    in module
    package MyCommon;

    use strict;
    use warnings;

    use Exporter;

    our ISA = 'Exporter';
    our EXPORT = qw(your_function_name1, your_function_name2, etc);

    sub your_function_name1 {
    my $in_string = $_[0];

    my $string2 = ucfirst lc $in_string;
    print "$string2\n";
    }

    ....

    In script:

    use MyCommon;

    your_function_name1('hello, packaged functionality');

    Joseph

    R. Joseph Newton Guest

  14. #14

    Default Re: Module Object and sub module function

    R. Joseph Newton wrote:
    >
    > Dan Muey wrote:
    >
    > >
    > >
    > > Basically I use the ParentName's $obj inside my functions
    > > and they are expecting it as the first arg.
    > >
    > > $obj->MyModule::function($arg); would be the coolest way
    > > (leaving my functions as sub function instead of sub
    > > NameSpace::Evil::function)
    > >
    > > Is this possible or am I just batty!?
    > >
    >
    > Absolutely on the mark! Bravo!
    >
    > Then catch it in the function with:
    > my $self = shift;
    [snip]

    Do you mean what you say Joseph?

    $obj->MyModule::function($arg)

    Whether MyModule is the base class or the subclass it goes
    against all principles of inheritance. $obj knows its own
    class, and a call to $obj->function() will pick the correct
    definitian of function() according to that class. Fully
    qualifying the function identifier makes nonsense of calling
    it via an object.

    Or am I missing something?

    Cheers,

    Rob



    Rob Dixon Guest

  15. #15

    Default Re: Module Object and sub module function

    Rob Dixon wrote:
    > R. Joseph Newton wrote:
    > >
    > > Dan Muey wrote:
    > >
    > > >
    > > >
    > > > Basically I use the ParentName's $obj inside my functions
    > > > and they are expecting it as the first arg.
    > > >
    > > > $obj->MyModule::function($arg); would be the coolest way
    > > > (leaving my functions as sub function instead of sub
    > > > NameSpace::Evil::function)
    > > >
    > > > Is this possible or am I just batty!?
    > > >
    > >
    > > Absolutely on the mark! Bravo!
    > >
    > > Then catch it in the function with:
    > > my $self = shift;
    >
    > [snip]
    >
    > Do you mean what you say Joseph?
    >
    > $obj->MyModule::function($arg)
    >
    > Whether MyModule is the base class or the subclass it goes
    > against all principles of inheritance. $obj knows its own
    > class, and a call to $obj->function() will pick the correct
    > definitian of function() according to that class. Fully
    > qualifying the function identifier makes nonsense of calling
    > it via an object.
    >
    > Or am I missing something?
    >
    > Cheers,
    >
    > Rob
    No-o-o-o, I was missing something--the package name still hanging
    onto the function name. Sorry, I sometimes just don't see what I
    would never think of looking for. All I saw was the object
    pointing to its method. Shoulda looked closer before I clapped.

    Joseph

    R. Joseph Newton Guest

  16. #16

    Default RE: Module Object and sub module function

    > > Any ideas what I'm missing ??
    >
    > Hi Dan,
    Howdy
    >
    > It sounds like you have a concept of the purpose of
    > inheritance, but some of it backward, and some of that magic
    A lto of it backwards! ;p
    > is irrelevant to Perl, since Perl lacks types. The ISA
    > relationship means that you can store objects of various
    > subtypes in a cntainer declared for their supertype, for
    > instance. Doesn't matter much in Perl, since containers can
    > hold scalars of any type anyway.
    >
    > The other advantage of inheritance, and a very relevant one,
    > is the ability to access *methods of base types* through
    > anobject declared as a subtype. The important point is that
    > ISA [pronounced always "izza'"] izza one-way relationship in
    > most cases. Anytime you slip behind the wheel of a
    > Lamborghini, you are getting into an automobile. Don't you
    > just wish the converse were true? No, you can't buy a Pinto
    > and do 165 mph down Main St. That method simply isn't
    > available in an object of the generic Automobile class.
    >
    > Joseph
    Ok if I explain it clearer than I have, I have a tendancy to
    ramble, maybe that will help:

    My Module is Nat.pm :

    package Net::Telnet::Cisco::Nat;


    Most of the functions in here use a Net::Telnet::Cisco Object
    that is logged in already to call Net::Telnet:Cisco 's methods,
    like enable() for instance.


    #!/usr/bin/perl -w

    use strict;
    use Net::Telnet::Cisco;
    use Net::Telnet::Cisco::Nat;

    #### start conf ##

    my $hst = '1.1.1.1';
    my $usr = '';
    my $pss = 'passwd';
    my $enablepasswd = $pss;

    #### end config ##

    my $ses = Net::Telnet::Cisco->new(Host => $hst);
    if($ses) {
    if($ses->login($usr,$pss)) {

    # here I want to use Net::Telnet::Cisco::Nat functions that can use $ses internally
    # this is where I'm really messing up, I can creat a new Object for it or call the functions directly but in #both cases I have to pass $ses eithe to the objetc ceration ot the funtion call:

    for(Net::Telnet::Cisco::Nat->ListNat($ses, {EnableInfo => [$enablepasswd]})) { print; }
    # or
    my $nat = new Net::Telnet::Cisco::Nat($ses);
    for($nat->ListNat({EnableInfo => [$enablepasswd]})) { print; }

    # they both work but I know I'm missing some major points of inheritance

    # do some more stuff with $ses and Net::Telnet:Cisco functions here

    } else { print "Can not login: ";print $ses->errmsg; }
    $ses->close;
    } else { print "Could not create initial session object to -$hst-\n"; }
    Dan Muey Guest

Similar Threads

  1. Which perl module to use for object persistence
    By Badari Kakumani in forum PERL Modules
    Replies: 4
    Last Post: February 1st, 03:01 PM
  2. Can't locate loadable object for module Tk::Event
    By balu422@yahoo.com in forum PERL Modules
    Replies: 6
    Last Post: July 19th, 05:45 PM
  3. Can't locate loadable object for module
    By Stefan in forum Perl / CGI
    Replies: 1
    Last Post: June 22nd, 06:56 PM
  4. Error calling MS-Access Module Function from SQL
    By Bob Barrows in forum ASP Database
    Replies: 1
    Last Post: November 25th, 06:22 AM
  5. Replies: 2
    Last Post: July 11th, 04:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139