Greetings all. This humble novice requests your assistance...

Imagine I have a base package (SomePackage.pm) that performs a number of functions against a website with a restful interface. That package is written in a perl OO way, with a new() constructor. Another script (caller.pl) will be the user of this package.

That said, I have a number of other sub modules in the base package: SomePackage::Auth.pm, SomePackage::Client.pm, SomePackage::Tickets.pm, etc.

Auth provides the methods to handle authentication to a given site. Client provides a LWP::UserAgent and any methods around certain functions the website offers. Tickets provides methods to create/modify/manage tickets on the site.

The goal I have here is that in the caller.pl, I instantiate the base package SomePackage->new; That sets up the base as well as setting up internal members to be a client (via SomePackage::Client) and ticket (via SomePackage::Ticket). It also has a method wrapper around SomePackage::Ticket's createTicket method:

package SomePackage; use strict; use warnings; use SomePackage::Auth; use SomePackage::Client; use SomePackage::Ticket; sub new { my $class = shift; my $self = {}; SomePackage::Auth->getCredentials; $self->{client} = SomePackage::Client->new; $self->{ticket} = SomePackage::Ticket->new; bless $self, $class; return $self; } sub createTicket { my $self = shift; my $class = shift; my $project = shift; return $self->{ticket}->createTicket($self, $project); }

Now, in caller.pl, I do something like

my $packObj = SomePackage->new; $packObj->createTicket($project);

On running caller.pl, I get use of unitialized value in subroutine entry. What is the proper way to structure classes/objects such that makes passing internal attributes/objects around painless? Am I going about this wrong way?

TIA
A perl OO newb

In reply to Objects and passing/calling methods by driador

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.