Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: 2-argument bless not working?!

by runrig (Abbot)
on Mar 31, 2004 at 01:27 UTC ( [id://341169]=note: print w/replies, xml ) Need Help??


in reply to why is a 2-argument bless not working in my situation

sub new { my ($self,$class)=@_; .... our $cache=Fiets::Cache->new();
There is no '$self' in the argument list when you call new like that. The assignment in new() should just be:
my ($class) = @_; # or # my $class = shift;
And your use of base is um, just wrong. 'use base' is meant to be set at a package level, and when you use it, you don't need the 'use *package*' line. Is your cachedir set once per program, and you want to inherit from Cache::FileCache or Cache::NullCache based on it per program run, or can it change per instance of an object? I'm not going to guess at what you want there.

Replies are listed 'Best First'.
Re: Re: 2-argument bless not working?!
by eXile (Priest) on Mar 31, 2004 at 01:44 UTC
      And your use of base is um, just wrong. 'use base' is meant to be set at a package level, and when you use it, you don't need the 'use *package*' line.
    I know 'use base' does an implicit 'require', but sometimes ...
      Is your cachedir set once per program, and you want to inherit from Cache::FileCache or Cache::NullCache based on it per program run, or can it change per instance of an object? I'm not going to guess at what you want there.
    That part of the program is working fine, the 'getvar' function checks %ENV and a config-file for clues on what to use. The whole program just uses 1 instance of Fiets::Cache.

    Thanks a lot, I totally missed the $self there!

      Are you sure you're inheritance chain is being set up properly? use and base are compile-time directives, which means that it doesn't matter where they appear in your code, they'll be executed before your code runs. If it's running as expected, that is, you're able to find the inherited methods when you call them on an instance of your subclass, then I would think you've got some multiple inheritance going on. If you truly want those to be set at runtime, I'd use require and manually adjust the @ISA array.


      "The dead do not recognize context" -- Kai, Lexx

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://341169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-19 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found