package Net::MessageBus::Message;

use 5.006;
use strict;
use warnings;

=head1 NAME

Net::MessageBus::Message - Pure Perl generic message queue

=head1 VERSION

Version 0.08


our $VERSION = '0.08';

use base qw(Class::Accessor);

__PACKAGE__->mk_ro_accessors(qw(type group sender payload));


This module implements a pure perl message bus message object

Example :

    use Net::MessageBus::Message;

    my $foo = Net::MessageBus::Message->new(
                            type => 'event',
                            payload => { some => 'complex strcture' },
                            sender => 'script1',
                            group => 'backend',


=head2 new

Creates a new Net::MessageBus::Message object



=item * type = A type assigned to the message

=item * payload = A complex perl structure / scalar but it cannot contain any objects

=item * sender = the name of the Net::MessageBus client that is sending the message

=item * group = the group to which this message belongs


B<Example> :
    my $foo = Net::MessageBus::Message->new(
                            type => 'event',
                            payload => { some => 'complex strcture' },
                            sender => 'script1',
                            group => 'backend',


sub new {
    my $class = shift;
    my %params = %{shift()};
    my $self = __PACKAGE__->SUPER::new({%params});
    return $self;

=head2 type

Returns the type of the message

B<Example> :
    my $type = $Message->type();
=head2 sender

Returns the sender of the message

B<Example> :

    my $type = $Message->sender();
=head2 group

Returns the group of the message

B<Example> :

    my $type = $Message->group();
=head2 payload

Returns the payload of the message 

B<Example> :

    my $type = $Message->payload();        

=head1 Private methods

=head2 serialize

Serializes the message for transport


sub serialize {
    my $self = shift;
    return {
            sender => $self->sender(),
            group  => $self->group(),
            type   => $self->type(),
            payload => $self->payload()

=head1 AUTHOR

Horea Gligan, C<< <gliganh at> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-net-MessageBus at>, or through
the web interface at L<>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::MessageBus::Message

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)


=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * Search CPAN





Copyright 2012 Horea Gligan.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See for more information.


1; # End of Net::MessageBus::Message