File Coverage

blib/lib/Slack/BlockKit/CompObj/Text.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition 6 6 100.0
subroutine 7 7 100.0
pod 0 1 0.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             package Slack::BlockKit::CompObj::Text 0.005;
2             # ABSTRACT: a Block Kit "composition object" for text
3 4     4   34 use Moose;
  4         10  
  4         39  
4 4     4   22381 use MooseX::StrictConstructor;
  4         10  
  4         40  
5              
6 4     4   16770 use Moose::Util::TypeConstraints qw(enum);
  4         36  
  4         47  
7              
8             with 'Slack::BlockKit::Role::Block';
9              
10             #pod =head1 OVERVIEW
11             #pod
12             #pod This is the text "composition object", which is used for non-rich text values
13             #pod in several places in Block Kit.
14             #pod
15             #pod =cut
16              
17 4     4   2536 use v5.36.0;
  4         19  
18              
19             #pod =attr type
20             #pod
21             #pod This required attribute must be either C<plain_text> or C<mrkdwn>, and
22             #pod instructs Slack how to interpret the text attribute.
23             #pod
24             #pod =cut
25              
26             has type => (
27             is => 'ro',
28             isa => enum([ qw( plain_text mrkdwn ) ]),
29             required => 1,
30             );
31              
32             #pod =attr text
33             #pod
34             #pod This is the string that is the text of the text object. There are length
35             #pod constraints enforced by Slack I<but not by this code>. Be mindful of those.
36             #pod
37             #pod =cut
38              
39             has text => (
40             is => 'ro',
41             isa => 'Str', # add length requirements, mayyyybe
42             required => 1,
43             );
44              
45             #pod =attr emoji
46             #pod
47             #pod This optional boolean option can determine whether emoji colon-codes are
48             #pod expanded within a C<plain_text> text object. Using this attribute on a
49             #pod C<mrkdwn> object will raise an exception.
50             #pod
51             #pod =cut
52              
53             has emoji => (
54             is => 'ro',
55             isa => 'Bool',
56             predicate => 'has_emoji',
57             );
58              
59             #pod =attr verbatim
60             #pod
61             #pod This optional boolean option can determine whether hyperlinks should be left
62             #pod unlinked within a C<mrkdown> text object. Using this attribute on a
63             #pod C<plain_text> object will raise an exception.
64             #pod
65             #pod =cut
66              
67             has verbatim => (
68             is => 'ro',
69             isa => 'Bool',
70             predicate => 'has_verbatim',
71             );
72              
73 7     7 0 43 sub BUILD ($self, @) {
  7         17  
  7         14  
74 7 100 100     421 Carp::croak("can't use 'emoji' with text composition object of type 'mrkdwn'")
75             if $self->type eq 'mrkdwn' and $self->has_emoji;
76              
77 6 100 100     257 Carp::croak("can't use 'verbatim' with text composition object of type 'plain_text'")
78             if $self->type eq 'plain_text' and $self->has_verbatim;
79             }
80              
81             sub as_struct ($self) {
82             return {
83             type => $self->type, # (not the object type, as with a block element)
84             text => q{} . $self->text,
85             ($self->has_emoji ? (emoji => Slack::BlockKit::boolify($self->emoji)) : ()),
86             ($self->has_verbatim ? (verbatim => Slack::BlockKit::boolify($self->verbatim)) : ()),
87             };
88             }
89              
90 4     4   35 no Moose;
  4         10  
  4         28  
91 4     4   1322 no Moose::Util::TypeConstraints;
  4         12  
  4         26  
92             __PACKAGE__->meta->make_immutable;
93              
94             __END__
95              
96             =pod
97              
98             =encoding UTF-8
99              
100             =head1 NAME
101              
102             Slack::BlockKit::CompObj::Text - a Block Kit "composition object" for text
103              
104             =head1 VERSION
105              
106             version 0.005
107              
108             =head1 OVERVIEW
109              
110             This is the text "composition object", which is used for non-rich text values
111             in several places in Block Kit.
112              
113             =head1 PERL VERSION
114              
115             This module should work on any version of perl still receiving updates from
116             the Perl 5 Porters. This means it should work on any version of perl
117             released in the last two to three years. (That is, if the most recently
118             released version is v5.40, then this module should work on both v5.40 and
119             v5.38.)
120              
121             Although it may work on older versions of perl, no guarantee is made that the
122             minimum required version will not be increased. The version may be increased
123             for any reason, and there is no promise that patches will be accepted to
124             lower the minimum required perl.
125              
126             =head1 ATTRIBUTES
127              
128             =head2 type
129              
130             This required attribute must be either C<plain_text> or C<mrkdwn>, and
131             instructs Slack how to interpret the text attribute.
132              
133             =head2 text
134              
135             This is the string that is the text of the text object. There are length
136             constraints enforced by Slack I<but not by this code>. Be mindful of those.
137              
138             =head2 emoji
139              
140             This optional boolean option can determine whether emoji colon-codes are
141             expanded within a C<plain_text> text object. Using this attribute on a
142             C<mrkdwn> object will raise an exception.
143              
144             =head2 verbatim
145              
146             This optional boolean option can determine whether hyperlinks should be left
147             unlinked within a C<mrkdown> text object. Using this attribute on a
148             C<plain_text> object will raise an exception.
149              
150             =head1 AUTHOR
151              
152             Ricardo SIGNES <cpan@semiotic.systems>
153              
154             =head1 COPYRIGHT AND LICENSE
155              
156             This software is copyright (c) 2024 by Ricardo SIGNES.
157              
158             This is free software; you can redistribute it and/or modify it under
159             the same terms as the Perl 5 programming language system itself.
160              
161             =cut