Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Moose Troubles

by three18ti (Scribe)
on May 27, 2012 at 21:07 UTC ( #972742=note: print w/ replies, xml ) Need Help??


in reply to Re: Moose Troubles
in thread Problem with Moose Dispatching Requests

Hello,
Thank you for the reply.

I guess my confusion is, ticket_list_response is an object that delegates methods, changing ticket_list_response to a method then won't allow me to call object methods later.

For instance, I want to initialize ticket_list_response attribute, then call count_tickets on the ticket_list_response object.

#!/usr/bin/perl use Kayako3::Staff; # this initializes Kayako3::Staff object, # performs the login, # parses the login response and stores the user session ID, # then initializes the info_response object which provides # all the info for id lookups later on my $help_desk = Kayako3::Staff->new({ username => 'bob', password => 'my_pass', api_url => 'http://example.com/staffapi?', }); # since the API requires integer ids, # I perform a lookup in separate steps for clarity # usually, I'll perform this all in one step: # $help_desk->get_ticket_list( # $help_desk->get_department_id("Support"), # $help_desk->get_ticket_status_id("New") # ); my $department_id = $help_desk->get_department_id("Support"); my $ticket_status_id = $help_desk->get_ticket_status_id("New"); $hd->get_ticket_list($department_id, $ticket_status_id) # once the ticket is loaded: print "Ticket count in " . $help_desk->ticket_list_response->department . ", for tickets with status " . $help_desk->ticket_list_response->status . ": " . $help_desk->get_ticket_count . "\n"; # sample output: # Ticket count in Support, for tickets with status New: 10 # then later on, I want to do the same thing # for a different department: my $department_id = $help_desk->get_department_id("Sales"); my $ticket_status_id = $help_desk->get_ticket_status_id("In progress"); $hd->get_ticket_list($department_id, $ticket_status_id) #Then I want to print the ticket count again, # for the new department, # but performing $help_desk->get_ticket_count # returns the same results above print "Ticket count in " . $help_desk->ticket_list_response->department . ", for tickets with status " . $help_desk->ticket_list_response->status . ": " . $help_desk->get_ticket_count . "\n"; # sample output: # Ticket count in Support, for tickets with status New: 10 # desired ouutput: # Ticket count in Sales, for tickets with status In Progress: 15

Usually, I wouldn't call $help_desk->_ticket_list_response->department directly, however, it is important to help illustrate my problem.

I don't want to call ticket_list_response directly because it only provides a place holder to store the Kayako3::Staff:Response::TicketList object.


Comment on Re^2: Moose Troubles
Download Code
Re^3: Moose Troubles
by CountZero (Bishop) on May 28, 2012 at 07:29 UTC
    When you want the ticket count for another department and/or another status shouldn't you start with a new object, rather than with an already existing object? Your _do_ticket_list method will only be called at the object's initialization, so changing the department id or the ticket status will go unnoticed and the ticket list is never refreshed.

    Reader beware: my Moose skills may be a bit rusty and the finer issues of builders and triggers may have escaped me.

    Update: Question: where does your $hd object come from? I never see you initialize it. Or is it perhaps a typo and did you mean $help_desk?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re^3: Moose Troubles
by moritz (Cardinal) on May 28, 2012 at 08:07 UTC
    I guess my confusion is, ticket_list_response is an object that delegates methods, changing ticket_list_response to a method then won't allow me to call object methods later.

    Then store the object that is now stored in ticket_list_response somewhere else (for example in a private attribute), and make ticket_list_response a method that does whatever you want it to do whenever it is called.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-08-23 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls