1# ============================================================================ 2package MooseX::App::Message::Block; 3# ============================================================================ 4 5use 5.010; 6use utf8; 7 8use namespace::autoclean; 9use Moose; 10 11use MooseX::App::Utils; 12 13use overload 14 '""' => "stringify"; 15 16has 'header' => ( 17 is => 'ro', 18 isa => 'MooseX::App::Types::MessageString', 19 predicate => 'has_header', 20); 21 22has 'type' => ( 23 is => 'ro', 24 isa => 'Str', 25 default => sub {'default'}, 26); 27 28has 'body' => ( 29 is => 'ro', 30 isa => 'MooseX::App::Types::MessageString', 31 predicate => 'has_body', 32); 33 34sub stringify { 35 my ($self) = @_; 36 37 my $message = ''; 38 $message .= $self->header."\n" 39 if $self->has_header; 40 41 $message .= $self->body."\n\n" 42 if $self->has_body; 43 44 return $message; 45} 46 47__PACKAGE__->meta->make_immutable; 481; 49 50__END__ 51 52=encoding utf8 53 54=head1 NAME 55 56MooseX::App::Message::Block - Message block 57 58=head1 DESCRIPTION 59 60A simple message block with a header and body 61 62=head1 METHODS 63 64=head2 header 65 66Read/set a header string 67 68=head2 has_header 69 70Check if a header is set 71 72=head2 body 73 74Read/set a body string 75 76=head2 has_body 77 78Check if a body is set 79 80=head2 type 81 82Read/set an arbitrary block type. Defaults to 'default' 83 84=head2 stringify 85 86Stringify a message block