Subject: | :ATTR(:name=>something) - Init Args not Working |
I have a class where I have:
--
...
my %username :ATTR( :name => 'username');
...
--
Class::Std, though, behaves as though no "init_arg" has been made,
because, I have tried:
--
...
my $class=MyClass->new({'username'=>'username'});
print $class->get_username().";
...
--
This returns:
--
Use of uninitalized at line XYZ
--
LONGER EXAMPLE:
Try setting up the two examples I've setup above:
--
lloy0076$ perl obj.pl
Use of uninitialized value in concatenation (.) or string at obj.pl line 27.
--
The documentation suggests that:
:ATTR( :name<name> )
Specifying the :name option is merely a convenient shorthand for
specifying all three of :get, :set, and :init_arg.
I've tried redoing my TransferObject.pm to use :name<name> syntax too.
Subject: | TransferObject.pm |
#!/usr/bin/perl
package YB::TransferObject;
use strict;
use warnings;
use base qw/SOAP::Lite Class::Std/;
my %username :ATTR(:name => 'username' :init);
my %password :ATTR(:name => 'password');
my %schema :ATTR(:name => 'schema');
my %token :ATTR(:name => 'token');
my %id :ATTR(:name => 'id');
my %posname :ATTR(:name => 'posname');
my %business_name :ATTR(:name => 'business_name');
my %store_id :ATTR(:name => 'store_id');
my %till_id :ATTR(:name => 'till_id');
my %customer_id :ATTR(:name => 'customer_id');
my %instruction :ATTR(:name => 'instruction');
my %object :ATTR(:name => 'object');
my %content :ATTR(:name => 'content');
sub get_encoded_params {
my $self=shift;
my @encoded_params = map(
{ print $_."\n"; }
(
$self->get_username,
$self->get_password,
$self->get_schema,
$self->get_token,
$self->get_id,
$self->get_posname,
$self->get_business_name,
$self->get_store_id,
$self->get_till_id,
$self->get_customer_id,
$self->get_instruction,
$self->get_object,
$self->get_content,
)
);
return @encoded_params;
}
sub encode :RESTRICTED {
my $self=shift;
my $string=shift;
if (!defined $string) {
$string="";
}
return SOAP::Data->type(string=>$string);
}
1;
Subject: | obj.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use YB::TransferObject;
my $x=YB::TransferObject->new({
'username' => 'username',
'password' => 'password',
'schema' => 'schema',
'token' => 'token',
'id' => 'id',
'posname' => 'posname',
'business_name' => 'business_name',
'store_id' => 'store_id',
'till_id' => 'till_id',
'customer_id' => 'customer_id',
'staff_id' => 'staff_id',
'instruction' => 'instruction',
'object' => 'object',
'content' => 'content',
});
print $x->get_username()."\n";