In my object constructor, I had an instruction to initialize two attributes at the same time:
($self->{token}, $self->{token_start}) = $self->_get_authorized_token();
So, I received the token and its start time together in one expression.
Now I'm trying to port my module to use Moo (se), and here I do not know how I should set these two related attributes at the same time. Some pseudo code would be like this:
has qw/token token_start/ => ( is => 'rw', default => shift->_get_authorized_token(); );
But how to declare 2 related attributes in Moo (se) ish way?
EDIT. I am showing the code of the _get_authorized_token method, maybe it will bring some ideas:
sub _get_authorized_token { my $self = shift; my $postData = { 'apikey' => $self->{key} }; my $url = $self->{base_url} . '/seller'; my $xml = $self->_post(url => $url, postdata => $postData, ); my $ref = XMLin($xml, SuppressEmpty => '' ); my $time = $ref->{Notification_Datetime}; my $token = $ref->{Notification_Data}{body}{token}; return ($token, $time); }
source share