Skip Menu |

This queue is for tickets about the Class-Std CPAN distribution.

Report information
The Basics
Id: 19427
Status: rejected
Priority: 0/
Queue: Class-Std

People
Owner: Nobody in particular
Requestors: lloy0076 [...] adam.com.au
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: v0.0.8
Fixed in: v0.0.8



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";
From: lloy0076 [...] adam.com.au
Hmmm... If I do: use base qw/Class::Std/; use base qw/SOAP::Lite/; ...my example works. If I reverse the above to become: use base qw/SOAP::Lite/; use base qw/Class::Std/; Then it doesn't work. I'm beginning to think that SOAP::Lite might be doing -something- to upset Class::Std but I'm not sure what. If there's something I can do to help debug this...tell me because I'm not sure what steps to take to provide better information.
From: DMUEY [...] cpan.org
On Tue May 23 03:55:01 2006, guest wrote: Show quoted text
> > I have a class where I have: > > -- > ... > my %username :ATTR( :name => 'username');
... Show quoted text
> The documentation suggests that: > > :ATTR( :name<name> )
you're doing ":name => 'whatever'" not " :name<name>" the way you are doing it you need to specify the init_arg key as well as well as defione th ekey better: 'name => 'whatever', This is not a bug, you're simply doing it wrong :)
On Tue May 23 03:55:01 2006, guest wrote: Show quoted text
> > I have a class where I have: > > my %username :ATTR( :name => 'username'); > > Class::Std, though, behaves as though no "init_arg" has been made,
[snip] attribute I have the same problem (and :ATTR( :name<username> ); behaves exactly the same). I've verified that the value of %attribute at the exit point of MODIFY_HASH_ATTRIBUTES() is correct. However, when the code arrives at the new() method provided by Class::Std, the entry in %attribute for my class has vanished (and no, DESCROY() has not been called) although the entries for Class::Std::SCR still exist.
Here's the source of the problem and a workaround. The class definition must precede the use. Presumably having it in a seperate .pm file acomplishes the same thing, although I haven't verified that. To see this, take the file t/perlattrs.t from the distribution (which passes, of course) and move the statements for package main to the top of the file. It now fails.
From: dmuey [...] cpan.org
On Tue Apr 24 14:33:12 2007, GLEACH wrote: Show quoted text
> Here's the source of the problem and a workaround. The class definition > must precede the use. Presumably having it in a seperate .pm file > acomplishes the same thing, although I haven't verified that. > > To see this, take the file t/perlattrs.t from the distribution (which > passes, of course) and move the statements for package main to the top > of the file. It now fails.
well sure, be cause them package main has no idea what package MyBase is, Its almost the same things as doing my $x = X->new(); require X; unless I'm misunderstanding (if I am please let me know the specifics) its as simple as yits not being done correctly and isn't really a Class::Std issue: multivac:~ dmuey$ perl -le 'CGI->new;require CGI;' Can't locate object method "new" via package "CGI" at -e line 1. multivac:~ dmuey$ perl -le 'require CGI;CGI->new;' multivac:~ dmuey$ please reopen if I've misunderstood and include details of what I missed, thanks!