Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Problem in private package

by kprasanna_79 (Hermit)
on Oct 28, 2008 at 23:32 UTC ( [id://720127]=perlquestion: print w/replies, xml ) Need Help??

kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Revered Monks,
I face the below problem when i use private package.
The error is Cant find the method Deliv
Actually i am calling this Deliv Package from the main package as below
push @delivs, new Deliv('deliverable ' . $_,$ini);
Also i have written this Deliv Package in the bottom of main package code.
package Deliv; use vars qw($AUTOLOAD); sub new { my $class = shift; my $self = bless {}, $class; my ($dev_sec,$cfg) = @_; $self->{source} = $cfg->val($dev_sec,'source'); $self->{related_job} = $cfg->val($dev_sec,'related_job'); return $self; }
I believe this is working fine in another code, but here it not. Any idea???
-Prasanna.K

Replies are listed 'Best First'.
Re: Problem in private package
by GrandFather (Saint) on Oct 28, 2008 at 23:54 UTC

    The following:

    use warnings; use strict; my @delivs; my $ini = 'wibble'; push @delivs, new Deliv ('deliverable ', $ini); $delivs[-1]->dump (); package Deliv; use vars qw($AUTOLOAD); sub new { my $class = shift; my $self = bless {}, $class; my ($dev_sec, $cfg) = @_; $self->{source} = $dev_sec; $self->{related_job} = $cfg; return $self; } sub dump { my ($self) = @_; print "$_: $self->{$_}\n" for sort keys %$self; }

    Prints:

    related_job: wibble source: deliverable

    as I would expect. What are you doing that is different?


    Perl reduces RSI - it saves typing
Re: Problem in private package
by chromatic (Archbishop) on Oct 29, 2008 at 05:44 UTC
    push @delivs, new Deliv('deliverable ' . $_,$ini);

    The indirect object syntax tends to fail horribly in curious ways, especially when you have everything in one file. I don't believe this will solve your entire problem, but you can avoid that ambiguity if your method calls look unambiguously like method calls:

    push @delivs, Deliv->new( 'deliverable ' . $_, $ini );
      chromatic
      It really worked..any idea why this worked and not the other
      -Prasanna.K

        Without seeing the actual error message, I can only guess that you already have a new function declared in the current package earlier in the file than this code, and Perl's calling that new instead of Deliv's new function.

Re: Problem in private package
by ikegami (Patriarch) on Oct 29, 2008 at 01:32 UTC
    Perl doesn't say "Cant find the method Deliv". It tends to spell "can't" correctly, for starters. Please provide the exact error message.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://720127]
Approved by SankoR
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found