Re: Need some help...

Rob Fugina <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
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
objtest2.pl (application/x-perl, 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/x-perl, 1.2 KB)
package Controller;

use POE;
use Carp;
use Params::Validate qw(:types validate);
use Data::Dumper;

use strict;
use warnings;

sub spawn
{
	my $type = shift;

	my %params = validate(@_, {
		Address => {
			type => SCALAR,
			regex => qr/^[\da-f]{2}\.[\da-f]{2}\.[\da-f]{2}$/i,
		},
		Alias => {
			type => SCALAR,
			regex => qr/^\w+$/,
		},
		Description => {
			type => SCALAR,
			optional => 1,
		},
		Schedules => {
			type => ARRAYREF,
			optional => 1,
			default => [],
		},
	});

	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 => [ 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];
	$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.