Re: Need some help...

Doug Greer <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
Hey all,

I'm just starting to learn POE, so I tried running the attached code and got
this warning:
Constant subroutine Controller::OBJECT redefined at
/usr/local/lib/perl5/site_perl/5.8.8/i686-linux/Params/Validate.pm line 5

It looks to me that the OBJECT constant is from POE is being interfered with
by the OBJECT constant from Params::Validate.  After removing the validate
method, the code seems to run OK.

Output from the code:

Dump params: $VAR1 = {
          'Alias' => 'lamp',
          'Address' => 'aa.aa.aa',
          'Description' => 'Lamp'
        };


$VAR1 = 'new object';
$VAR2 = bless( {
                 'address' => 'AA.AA.AA'
               }, 'Controller' );
$VAR1 = 'in _start, want object, heap';
$VAR2 = bless( {
                 'address' => 'AA.AA.AA'
               }, 'Controller' );
$VAR3 = {
          'description' => 'Lamp',
          'alias' => 'lamp'
        };
$VAR1 = 'dump of session';
$VAR2 = bless( [
                 {
                   'description' => 'Lamp',
                   'alias' => 'lamp'
                 },
                 {},
                 {
                   '_start' => [
                                 bless( {
                                          'address' => 'AA.AA.AA'
                                        }, 'Controller' ),
                                 '_start'
                               ]
                 }
               ], 'POE::Session' );



Sincerely,
Doug Greer



On Sat, Jun 13, 2009 at 8:47 PM, Rob Fugina <[email protected]> wrote:

> I'm attaching my actual module, minus the path (for your convenience),
> and a test script that demonstrates the error.  It doesn't suffer from
> the original array slice problem.  I've done this before (object
> states, that is), but they were fragile even then -- or they are now,
> anyway.  I'm sure there's something simple or stupid I'm missing...
>
> Rob
>
test_controller.pl (application/octet-stream, 271 B)
#!/usr/local/bin/perl

use POE;
use Data::Dumper;
use Controller;

use strict;
use warnings;

my $session = Controller->spawn(
	Address => 'aa.aa.aa',
	Alias => 'lamp',
	Description => 'Lamp',
	);

print Dumper('dump of session', $session);

POE::Kernel->run();

exit;
Controller.pm (application/octet-stream, 960 B)
package Controller;

use POE;
use Carp;
use Data::Dumper;

use strict;
use warnings;

sub spawn
{
	my $type = shift;

	my %params = @_;	
	print "Dump params: ".Dumper(\%params)."\n\n";

	my $self = $type->new(
		address => uc($params{Address}),
		);

	croak "Object creation failed" unless $self;

	print Dumper('new object', $self);

	POE::Session->create(
		object_states => [
			$self => [ _start => qw( _start ) ],
			
			],
		heap => {
			alias => $params{Alias},
			description => $params{Description} || uc($params{Address}),
			},
		);
}


sub new
{
	my $type = shift;
	my $self = bless { @_ }, $type;
	return $self;
}

###

sub address
{
	my $self = shift;
	return $self->{address};
}

###

sub _start
{
	my ($kernel, $self, $heap) = @_[KERNEL, OBJECT, HEAP];
	$self = $_[OBJECT];
	$kernel->alias_set($heap->{alias}) if defined $heap->{alias};
	print Dumper('in _start, want object, heap', $self, $heap);
	$kernel->alias_set($self->address);
}


1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.