File Coverage

blib/lib/Slack/BlockKit/Block/RichText/Preformatted.pm
Criterion Covered Total %
statement 14 19 73.6
branch n/a
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 19 26 73.0


line stmt bran cond sub pod time code
1             package Slack::BlockKit::Block::RichText::Preformatted 0.005;
2             # ABSTRACT: a Block Kit preformatted rich text element
3              
4 4     4   31 use Moose;
  4         11  
  4         106  
5 4     4   23265 use MooseX::StrictConstructor;
  4         11  
  4         113  
6              
7 4     4   14949 use Slack::BlockKit::Types qw(ExpansiveElementList Pixels);
  4         10  
  4         48  
8              
9             #pod =head1 OVERVIEW
10             #pod
11             #pod This is a "preformatted" element, which basically just means a code block of
12             #pod the sort you'd get with C<``` ... ```> in Markdown.
13             #pod
14             #pod =cut
15              
16 4     4   10869 use v5.36.0;
  4         15  
17              
18             #pod =attr border
19             #pod
20             #pod This property is meant to be the number of pixels wide the border is. In
21             #pod practice, the author has only found this to cause Slack to reject Block Kit
22             #pod structures.
23             #pod
24             #pod =cut
25              
26             has border => (
27             is => 'ro',
28             isa => Pixels(),
29             );
30              
31             #pod =attr elements
32             #pod
33             #pod This is an arrayref of rich text elements. For more information, see the slack
34             #pod Block Kit documentation.
35             #pod
36             #pod =cut
37              
38             # Now, the documentation says that "link" elements inside "preformatted" blocks
39             # are special, and that while normal "link" elements can have (bold, italic,
40             # strike, code) styles, they *can't* have (strike) or (code) when inside a
41             # preformatted block.
42             #
43             # Testing shows this is not true, so I have not special-cased anything. (I
44             # actually wrote the code, but then experiments showed it was not enforced. I
45             # filed a bug.)
46             has elements => (
47             isa => ExpansiveElementList(),
48             traits => [ 'Array' ],
49             handles => { elements => 'elements' },
50             );
51              
52 0     0 0   sub as_struct ($self) {
  0            
  0            
53             return {
54             type => 'rich_text_preformatted',
55 0           elements => [ map {; $_->as_struct } $self->elements ],
  0            
56             };
57             }
58              
59 4     4   30 no Moose;
  4         11  
  4         27  
60             __PACKAGE__->meta->make_immutable;
61              
62             __END__
63              
64             =pod
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Slack::BlockKit::Block::RichText::Preformatted - a Block Kit preformatted rich text element
71              
72             =head1 VERSION
73              
74             version 0.005
75              
76             =head1 OVERVIEW
77              
78             This is a "preformatted" element, which basically just means a code block of
79             the sort you'd get with C<``` ... ```> in Markdown.
80              
81             =head1 PERL VERSION
82              
83             This module should work on any version of perl still receiving updates from
84             the Perl 5 Porters. This means it should work on any version of perl
85             released in the last two to three years. (That is, if the most recently
86             released version is v5.40, then this module should work on both v5.40 and
87             v5.38.)
88              
89             Although it may work on older versions of perl, no guarantee is made that the
90             minimum required version will not be increased. The version may be increased
91             for any reason, and there is no promise that patches will be accepted to
92             lower the minimum required perl.
93              
94             =head1 ATTRIBUTES
95              
96             =head2 border
97              
98             This property is meant to be the number of pixels wide the border is. In
99             practice, the author has only found this to cause Slack to reject Block Kit
100             structures.
101              
102             =head2 elements
103              
104             This is an arrayref of rich text elements. For more information, see the slack
105             Block Kit documentation.
106              
107             =head1 AUTHOR
108              
109             Ricardo SIGNES <cpan@semiotic.systems>
110              
111             =head1 COPYRIGHT AND LICENSE
112              
113             This software is copyright (c) 2024 by Ricardo SIGNES.
114              
115             This is free software; you can redistribute it and/or modify it under
116             the same terms as the Perl 5 programming language system itself.
117              
118             =cut