Skip Menu |
 

This queue is for tickets about the Object-InsideOut CPAN distribution.

Report information
The Basics
Id: 60427
Status: rejected
Priority: 0/
Queue: Object-InsideOut

People
Owner: Nobody in particular
Requestors: tao.yang [...] bankofamerica.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Initiate attributes
Date: Tue, 17 Aug 2010 12:30:00 -0400
To: bug-Object-InsideOut [...] rt.cpan.org
From: "Yang, Tao" <tao.yang [...] bankofamerica.com>
Download (untitled) / with headers
text/plain 702b
Hello, I have three attributes defined as: my @tier_name : Field : Arg('Name' => 'tier_name') ; my @subnet : Field : Arg('Name' => 'subnet') ; my @action : Field : Get(action) ; In my init :Init(), I pass in a args reference as below: $args = { tier_name => 'sl-1', action => 'show', subnet => '127.0.0.1', }; I am trying do something like this: for $key (keys %$args) { $self->set( \@$key, $args->{$key}); } In other word, can the variable name itself be a variable? I always gets error. I am not sure if this is supported in object:insideout. Thanks
Download (untitled) / with headers
text/plain 926b
First of all, in the future, please just email me directly with programming questions. You aren't reporting a bug. In answer to your question, a variable name cannot be a variable in the way you're trying to do it. You would need something like this: for $key (keys %$args) { eval '$self->set( \@' . $key . ', $args->{$key})'; } However, even this is overkill for your purposes. Object::InsideOut will do all the work for you. package Foo; { use Object::InsideOut; my @tier_name : Field : Arg('Name' => 'tier_name') ; my @subnet : Field : Arg('Name' => 'subnet') ; my @action : Field : Arg('Name' => 'action') : Get(action) ; # You don't need an :Init subroutine } package main; my $args = { tier_name => 'sl-1', action => 'show', subnet => '127.0.0.1', }; my $obj = Foo->new($args); print('Action is: ' . $obj->action() . "\n"); At any rate, thanks for using Object::InsideOut
Subject: RE: [rt.cpan.org #60427] Initiate attributes
Date: Tue, 17 Aug 2010 13:56:29 -0400
To: bug-Object-InsideOut [...] rt.cpan.org
From: "Yang, Tao" <tao.yang [...] bankofamerica.com>
Download (untitled) / with headers
text/plain 1.6k
Thanks for the quick reply. My application requires to use additional initial sub to do some special setup. I try your suggestion: eval '$self->set( \@' . $key . ', $args->{$key})'; I did not get any error now. But the actual data has not been set. If I do something like xxxx = $self->action(), I always get message like " Use of uninitialized value xxx". That is why I know it is not setup correctly. I also use " if (defined $self->action)" to check if data is set. It also shows data has not been set. Any clue? Thanks Show quoted text
-----Original Message----- From: Jerry D. Hedden via RT [mailto:bug-Object-InsideOut@rt.cpan.org] Sent: Tuesday, August 17, 2010 1:10 PM To: Yang, Tao Subject: [rt.cpan.org #60427] Initiate attributes <URL: https://rt.cpan.org/Ticket/Display.html?id=60427 > First of all, in the future, please just email me directly with programming questions. You aren't reporting a bug. In answer to your question, a variable name cannot be a variable in the way you're trying to do it. You would need something like this: for $key (keys %$args) { eval '$self->set( \@' . $key . ', $args->{$key})'; } However, even this is overkill for your purposes. Object::InsideOut will do all the work for you. package Foo; { use Object::InsideOut; my @tier_name : Field : Arg('Name' => 'tier_name') ; my @subnet : Field : Arg('Name' => 'subnet') ; my @action : Field : Arg('Name' => 'action') : Get(action) ; # You don't need an :Init subroutine } package main; my $args = { tier_name => 'sl-1', action => 'show', subnet => '127.0.0.1', }; my $obj = Foo->new($args); print('Action is: ' . $obj->action() . "\n"); At any rate, thanks for using Object::InsideOut


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.