File Coverage

blib/lib/Net/Async/Slack/EventType.pm
Criterion Covered Total %
statement 25 34 73.5
branch 3 12 25.0
condition n/a
subroutine 7 9 77.7
pod 0 2 0.0
total 35 57 61.4


line stmt bran cond sub pod time code
1             package Net::Async::Slack::EventType;
2              
3 106     106   392996 use strict;
  106         271  
  106         4126  
4 106     106   718 use warnings;
  106         229  
  106         7745  
5              
6             our $VERSION = '0.015'; # VERSION
7              
8 106     106   59532 use Log::Any qw($log);
  106         1091589  
  106         608  
9              
10 106     106   347958 use Check::UnitCheck;
  106         406624  
  106         545  
11             our %REGISTERED_TYPES;
12              
13             sub import {
14 795     795   2184 my ($class, @args) = @_;
15 795         2520 my ($pkg) = caller;
16              
17             # Bail out unless we're called directly, we don't want the import to propagate
18             # to subclasses.
19 795 100       16411 return unless $class eq __PACKAGE__;
20              
21             # Register and set up inheritance for things that import us directly,
22             # deferring the type registration until the module has been fully compiled.
23             Check::UnitCheck::unitcheckify(sub {
24 401 50   401   3950 die 'Already registered ' . $pkg->type if exists $REGISTERED_TYPES{$pkg->type};
25 401         1430 $REGISTERED_TYPES{$pkg->type} = $pkg;
26 106     106   16783 { no strict 'refs'; push @{$pkg . '::ISA'}, __PACKAGE__; }
  106         235  
  106         35628  
  401         810  
  401         703  
  401         5425  
27 401         3830 }) ;
28 401         33403 return;
29             }
30              
31             sub from_json {
32 0     0 0   my ($self, $data) = @_;
33 0           $log->tracef('Looking for type %s with available %s', $data->{type}, join ',', sort keys %REGISTERED_TYPES);
34 0 0         return undef unless my $class = $REGISTERED_TYPES{$data->{type}};
35 0           for (qw(user channel team source_team)) {
36 0 0         if(my $item = delete $data->{$_}) {
37 0 0         $data->{$_ . '_id'} = ref($item) ? $item->{id} : $item;
38 0 0         $data->{$_} = $item if ref($item);
39             }
40             }
41 0           return $class->new(%$data);
42             }
43              
44 0     0 0   sub new { bless { @_[1..$#_] }, $_[0] }
45              
46             1;
47