File Coverage

blib/lib/Net/Async/Slack/Message.pm
Criterion Covered Total %
statement 12 32 37.5
branch 0 8 0.0
condition 0 10 0.0
subroutine 4 9 44.4
pod 0 5 0.0
total 16 64 25.0


line stmt bran cond sub pod time code
1             package Net::Async::Slack::Message;
2              
3 2     2   404599 use strict;
  2         4  
  2         87  
4 2     2   22 use warnings;
  2         3  
  2         191  
5              
6             our $VERSION = '0.015'; # VERSION
7              
8 2     2   11 use Scalar::Util qw(weaken);
  2         5  
  2         151  
9 2     2   652 use JSON::MaybeXS;
  2         14355  
  2         989  
10              
11             my $json = JSON::MaybeXS->new;
12              
13             sub new {
14 0     0 0   my $class = shift;
15 0           my $self = bless { @_ }, $class;
16 0           weaken $self->{slack};
17 0           $self
18             }
19              
20 0     0 0   sub slack { shift->{slack} }
21 0     0 0   sub channel { shift->{channel} }
22 0     0 0   sub thread_ts { shift->{thread_ts} }
23              
24             sub update {
25 0     0 0   my ($self, %args) = @_;
26 0 0 0       die 'You need to pass either text or attachments' unless $args{text} || $args{attachments} || $args{blocks};
      0        
27              
28 0   0       $args{text} //= '';
29 0           my @content;
30 0           push @content, token => $self->slack->token;
31 0           push @content, channel => $self->channel;
32 0           push @content, ts => $self->thread_ts;
33              
34 0 0         push @content, text => $args{text} if defined $args{text};
35 0 0         push @content, attachments => $json->encode($args{attachments}) if $args{attachments};
36 0 0         push @content, blocks => $json->encode($args{blocks}) if $args{blocks};
37 0   0       $args{as_user} //= 'true';
38 0           push @content, $_ => $args{$_} for grep exists $args{$_}, qw(parse link_names unfurl_links unfurl_media as_user reply_broadcast);
39 0           $self->slack->http_post(
40             $self->slack->endpoint(
41             'chat_update',
42             ),
43             \@content,
44             )
45             }
46              
47             1;