The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Message::Board - Data object for Message board.

SYNOPSIS

 use Data::Message::Board;

 my $obj = Data::Message::Board->new(%params);
 my $author = $obj->author;
 my $comments_ar = $obj->comments;
 my $date = $obj->date;
 my $id = $obj->id;
 my $message = $obj->message;

METHODS

new

 my $obj = Data::Message::Board->new(%params);

Constructor.

  • author

    Author object which is Data::Person instance.

    It's required.

  • comments

    Message board comments which are Data::Mesaage::Board::Comment instances.

    Default value is [].

  • date

    Date of comment which is DateTime instance.

    It's required.

  • id

    Id.

    Default value is undef.

  • message

    Main comment message. Max length of message is 4096 character.

    It's required.

Returns instance of object.

author

 my $author = $obj->author;

Get author instance.

Returns Data::Person instance.

comments

 my $comments_ar = $obj->comments;

Get message board comments.

Returns reference to array with Data::Message::Board::Comment instances.

date

 my $date = $obj->date;

Get datetime of comment.

Returns DateTime instance.

id

 my $id = $obj->id;

Get comment id.

Returns natural number.

 my $message = $obj->message;

Get comment message.

Returns string.

ERRORS

 new():
         From Mo::utils::check_array_object():
                 Parameter 'comments' must be a array.
                         Value: %s
                         Reference: %s
                 Comment isn't 'Data::Message::Board::Comment' object.
                         Value: %s
                         Reference: %s
         From Mo::utils::check_isa():
                 Parameter 'author' must be a 'Data::Person' object.
                         Value: %s
                         Reference: %s
                 Parameter 'date' must be a 'DateTime' object.
                         Value: %s
                         Reference: %s
         From Mo::utils::check_length():
                 Parameter 'message' has length greater than '4096'.
                         Value: %s
         From Mo::utils::check_number_id():
                 Parameter 'id' must be a natural number.
                         Value: %s
         From Mo::utils::check_required():
                 Parameter 'author' is required.
                 Parameter 'date' is required.
                 Parameter 'message' is required.

EXAMPLE

 use strict;
 use warnings;

 use Data::Person;
 use Data::Message::Board;
 use Data::Message::Board::Comment;
 use DateTime;
 use Unicode::UTF8 qw(decode_utf8 encode_utf8);

 my $dt = DateTime->now;
 my $dt_comment1 = $dt->clone->add('minutes' => 5);
 my $dt_comment2 = $dt_comment1->clone->add('seconds' => 34);
 my $obj = Data::Message::Board->new(
         'author' => Data::Person->new(
                 'email' => 'skim@cpan.org',
                 'name' => decode_utf8('Michal Josef Špaček'),
         ),
         'comments' => [
                 Data::Message::Board::Comment->new(
                         'author' => Data::Person->new(
                                 'email' => 'bar@example.com',
                                 'name' => decode_utf8('St. John'),
                         ),
                         'date' => $dt_comment1,
                         'id' => 7,
                         'message' => 'I am fine.',
                 ),
                 Data::Message::Board::Comment->new(
                         'author' => Data::Person->new(
                                 'email' => 'foo@example.com',
                                 'name' => decode_utf8('John Wick'),
                         ),
                         'date' => $dt_comment2,
                         'id' => 6,
                         'message' => 'Not bad.',
                 ),
         ],
         'date' => $dt,
         'id' => 1,
         'message' => 'How are you?',
 );

 # Print out.
 print 'Author name: '.encode_utf8($obj->author->name)."\n";
 print 'Author email: '.$obj->author->email."\n";
 print 'Date: '.$obj->date."\n";
 print 'Id: '.$obj->id."\n";
 print 'Message: '.$obj->message."\n";
 print "Comments:\n";
 map {
         print "\tAuthor name: ".$_->author->name."\n";
         print "\tDate: ".$_->date."\n";
         print "\tId: ".$_->id."\n";
         print "\tComment: ".$_->message."\n\n";
 } @{$obj->comments};

 # Output:
 # Author name: Michal Josef Špaček
 # Author email: skim@cpan.org
 # Date: 2024-05-27T18:10:55
 # Id: 1
 # Message: How are you?
 # Comments:
 #         Author name: St. John
 #         Date: 2024-05-27T18:15:55
 #         Id: 7
 #         Comment: I am fine.
 # 
 #         Author name: John Wick
 #         Date: 2024-05-27T18:16:29
 #         Id: 6
 #         Comment: Not bad.
 # 

DEPENDENCIES

Mo, Mo::utils.

REPOSITORY

https://github.com/michal-josef-spacek/Data-Message-Board

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.01