File Coverage

blib/lib/Slack/BlockKit/Block/Section.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 4 100.0
condition 5 6 83.3
subroutine 9 9 100.0
pod 0 1 0.0
total 46 48 95.8


line stmt bran cond sub pod time code
1             package Slack::BlockKit::Block::Section 0.005;
2             # ABSTRACT: a Block Kit section block, used to collect text
3              
4 4     4   24 use Moose;
  4         7  
  4         33  
5 4     4   28760 use MooseX::StrictConstructor;
  4         8  
  4         37  
6              
7             with 'Slack::BlockKit::Role::Block';
8              
9             #pod =head1 OVERVIEW
10             #pod
11             #pod This represents a C<section> block, which is commonly used to contain text to
12             #pod be sent. Don't confuse this class with L<Slack::BlockKit::Block::RichText> or
13             #pod L<Slack::BlockKit::Block::RichText::Section>, which are used to present I<rich>
14             #pod text. A "normal" section block can only present rich text in the form of
15             #pod C<mrkdwn>-type text objects.
16             #pod
17             #pod =cut
18              
19 4     4   14949 use v5.36.0;
  4         15  
20              
21 4     4   24 use Moose::Util::TypeConstraints qw(class_type);
  4         6  
  4         41  
22 4     4   1921 use MooseX::Types::Moose qw(ArrayRef);
  4         26  
  4         49  
23              
24             # I have intentionally omitted "accessory" for now.
25              
26             #pod =attr text
27             #pod
28             #pod This is a L<text composition object|Slack::BlockKit::CompObj::Text> with the
29             #pod text to be displayed in this block.
30             #pod
31             #pod If you provide C<text>, then providing C<fields> is an error and will cause an
32             #pod exception to be raised.
33             #pod
34             #pod =cut
35              
36             has text => (
37             is => 'ro',
38             isa => class_type('Slack::BlockKit::CompObj::Text'),
39             predicate => 'has_text',
40             );
41              
42             #pod =attr fields
43             #pod
44             #pod This is a an arrayref of L<text composition
45             #pod object|Slack::BlockKit::CompObj::Text> with the text to be displayed in this
46             #pod block. These objects will be displayed in two columns, generally.
47             #pod
48             #pod If you provide C<fields>, then providing C<text> is an error and will cause an
49             #pod exception to be raised.
50             #pod
51             #pod =cut
52              
53             has fields => (
54             isa => ArrayRef([ class_type('Slack::BlockKit::CompObj::Text') ]),
55             predicate => 'has_fields',
56             traits => [ 'Array' ],
57             handles => { fields => 'elements' },
58             );
59              
60 3     3 0 6 sub BUILD ($self, @) {
  3         6  
  3         5  
61 3 100 100     176 Carp::croak("neither text nor fields provided in Slack::BlockKit::Block::Section construction")
62             unless $self->has_text or $self->has_fields;
63              
64 2 100 66     102 Carp::croak("both text and fields provided in Slack::BlockKit::Block::Section construction")
65             if $self->has_text and $self->has_fields;
66             }
67              
68             sub as_struct ($self) {
69             return {
70             type => 'section',
71             ($self->has_text
72             ? (text => $self->text->as_struct)
73             : ()),
74             ($self->has_fields
75             ? (fields => [ map {; $_->as_struct } $self->fields ])
76             : ()),
77             };
78             }
79              
80 4     4   21781 no Moose;
  4         8  
  4         43  
81 4     4   966 no Moose::Util::TypeConstraints;
  4         8  
  4         19  
82 4     4   510 no MooseX::Types::Moose;
  4         6  
  4         195  
83             __PACKAGE__->meta->make_immutable;
84              
85             __END__
86              
87             =pod
88              
89             =encoding UTF-8
90              
91             =head1 NAME
92              
93             Slack::BlockKit::Block::Section - a Block Kit section block, used to collect text
94              
95             =head1 VERSION
96              
97             version 0.005
98              
99             =head1 OVERVIEW
100              
101             This represents a C<section> block, which is commonly used to contain text to
102             be sent. Don't confuse this class with L<Slack::BlockKit::Block::RichText> or
103             L<Slack::BlockKit::Block::RichText::Section>, which are used to present I<rich>
104             text. A "normal" section block can only present rich text in the form of
105             C<mrkdwn>-type text objects.
106              
107             =head1 PERL VERSION
108              
109             This module should work on any version of perl still receiving updates from
110             the Perl 5 Porters. This means it should work on any version of perl
111             released in the last two to three years. (That is, if the most recently
112             released version is v5.40, then this module should work on both v5.40 and
113             v5.38.)
114              
115             Although it may work on older versions of perl, no guarantee is made that the
116             minimum required version will not be increased. The version may be increased
117             for any reason, and there is no promise that patches will be accepted to
118             lower the minimum required perl.
119              
120             =head1 ATTRIBUTES
121              
122             =head2 text
123              
124             This is a L<text composition object|Slack::BlockKit::CompObj::Text> with the
125             text to be displayed in this block.
126              
127             If you provide C<text>, then providing C<fields> is an error and will cause an
128             exception to be raised.
129              
130             =head2 fields
131              
132             This is a an arrayref of L<text composition
133             object|Slack::BlockKit::CompObj::Text> with the text to be displayed in this
134             block. These objects will be displayed in two columns, generally.
135              
136             If you provide C<fields>, then providing C<text> is an error and will cause an
137             exception to be raised.
138              
139             =head1 AUTHOR
140              
141             Ricardo SIGNES <cpan@semiotic.systems>
142              
143             =head1 COPYRIGHT AND LICENSE
144              
145             This software is copyright (c) 2024 by Ricardo SIGNES.
146              
147             This is free software; you can redistribute it and/or modify it under
148             the same terms as the Perl 5 programming language system itself.
149              
150             =cut