Hi, this is probably very simple, but my brain is starting to smoke because I just can't find what I'm doing wrong. I want to make Fiets::Cache an inherited class of Cache::Cache (I want to do some extra stuff in the get and set functions), so I wrote this constructor:
package Fiets::Cache; use strict; use warnings; ... sub new { my ($self,$class)=@_; my $cdir = Fiets::getvar('cachedir'); if ($cdir) { use Cache::FileCache; use base qw(Cache::FileCache); $self=Cache::FileCache->new({ 'cache_root' => $cdir, 'default_expires_in' => '4 h' }); } else { use Cache::NullCache; use base qw(Cache::NullCache); $self=Cache::NullCache->new({ 'default_expires_in' => '4 h', }); } bless ($self,$class); return $self; } ... 1;
This code is called from Fiets.pm like this:
use Fiets::Cache; our $cache=Fiets::Cache->new();
Fiets.pm and $Fiets::cache are used in my main-program, and other libraries in the Fiets::-hierarchy.

Now my problem: Calls like $Fiets::cache->get($id) in other libraries will return errors (via an Exception-handler) like:
'Can\'t locate object method "get" via package "main"'
If I change the two-argument bless into bless($self), these errors disappear and in the debugger I can see (with 'm') that my Fiets::Cache indeed has its own new method and a couple of other methods of it's own and inherits a whole bunch of methods for Cache::Cache.

But I still don't know why the two-argument bless will not work for me. This must be something stupid and simple I guess.

PS: 'Fiets' is just a hypothetical name.

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

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.