File Coverage

blib/lib/Slack/BlockKit/Role/Block.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Slack::BlockKit::Role::Block 0.005;
2             # ABSTRACT: a Block Kit block object
3              
4 4     4   2910 use Moose::Role;
  4         8  
  4         36  
5              
6 4     4   12411 use v5.36.0;
  4         24  
7              
8             #pod =head1 OVERVIEW
9             #pod
10             #pod This role is composed by any "block" in Block Kit. The definition of what is
11             #pod or isn't a block is not well defined, but here it means "anything that can be
12             #pod turned into a struct and has an optional C<block_id> attribute".
13             #pod
14             #pod =attr block_id
15             #pod
16             #pod This is an optional string, which will become the C<block_id> of this object in
17             #pod the emitted structure.
18             #pod
19             #pod =cut
20              
21             has block_id => (
22             is => 'ro',
23             isa => 'Str',
24             predicate => 'has_block_id',
25             );
26              
27             #pod =method as_struct
28             #pod
29             #pod All classes composing Block must provide an C<as_struct> method. Its result is
30             #pod decorated so that the C<block_id> of this block, if any, is added to the
31             #pod returned structure.
32             #pod
33             #pod =cut
34              
35             requires 'as_struct';
36              
37             around as_struct => sub ($orig, $self, @rest) {
38             my $struct = $self->$orig(@rest);
39              
40             if ($self->has_block_id) {
41             $struct->{block_id} = $self->block_id;
42             }
43              
44             return $struct;
45             };
46              
47 4     4   23 no Moose::Role;
  4         9  
  4         24  
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             Slack::BlockKit::Role::Block - a Block Kit block object
59              
60             =head1 VERSION
61              
62             version 0.005
63              
64             =head1 OVERVIEW
65              
66             This role is composed by any "block" in Block Kit. The definition of what is
67             or isn't a block is not well defined, but here it means "anything that can be
68             turned into a struct and has an optional C<block_id> attribute".
69              
70             =head1 PERL VERSION
71              
72             This module should work on any version of perl still receiving updates from
73             the Perl 5 Porters. This means it should work on any version of perl
74             released in the last two to three years. (That is, if the most recently
75             released version is v5.40, then this module should work on both v5.40 and
76             v5.38.)
77              
78             Although it may work on older versions of perl, no guarantee is made that the
79             minimum required version will not be increased. The version may be increased
80             for any reason, and there is no promise that patches will be accepted to
81             lower the minimum required perl.
82              
83             =head1 ATTRIBUTES
84              
85             =head2 block_id
86              
87             This is an optional string, which will become the C<block_id> of this object in
88             the emitted structure.
89              
90             =head1 METHODS
91              
92             =head2 as_struct
93              
94             All classes composing Block must provide an C<as_struct> method. Its result is
95             decorated so that the C<block_id> of this block, if any, is added to the
96             returned structure.
97              
98             =head1 AUTHOR
99              
100             Ricardo SIGNES <cpan@semiotic.systems>
101              
102             =head1 COPYRIGHT AND LICENSE
103              
104             This software is copyright (c) 2024 by Ricardo SIGNES.
105              
106             This is free software; you can redistribute it and/or modify it under
107             the same terms as the Perl 5 programming language system itself.
108              
109             =cut