| IM-Engine documentation | Contained in the IM-Engine distribution. |
IM::Engine::Incoming - a message we have received
An instance of IM::Engine::User which represents the sender of this incoming message.
Constructs a IM::Engine::Outgoing message that represents a reply to this incoming message.
my $outgoing = $incoming->reply("Sorry, I didn't understand.");
You can also pass in a hash of attributes for constructing the outgoing message.
| IM-Engine documentation | Contained in the IM-Engine distribution. |
package IM::Engine::Incoming; use Moose; use MooseX::StrictConstructor; extends 'IM::Engine::Message'; use IM::Engine::Outgoing; use constant _reply_class => 'IM::Engine::Outgoing'; has sender => ( is => 'ro', isa => 'IM::Engine::User', required => 1, ); sub reply { my $self = shift; my %args; if (@_ == 1) { %args = (message => $_[0]); } else { %args = @_; } Carp::carp("Incoming->reply constructs an Outgoing object for you; it does not automatically send it") if !defined(wantarray); my $outgoing = $self->_reply_class->new( $self->_contextual_reply_arguments, %args, ); return $outgoing; } sub _contextual_reply_arguments { my $self = shift; return ( incoming => $self, recipient => $self->sender, inner, ); } __PACKAGE__->meta->make_immutable; no Moose; 1; __END__