Intercom.pm

filter: Statementstmt 37.9% 391 / 1030 Branchbran 0.0% 0 / 570 Conditioncond 0.0% 0 / 263 MC/DCmcdc 0.0% 0 / 122 Subroutinesub 88.8% 127 / 143 Podpod n/a totaltotal 24.3% 518 / 2128 CC 388 SCAR 70.2
CC
388
Cov
21%
user_create_or_update
3379.3
create_message
2536.3
event_create
1684.5
CRAP 1119.7
↑ Summary Intercom/User.pm »
1 2 ▶use Moops -strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
2  
3 # ABSTRACT: interfaces with Intercom.io
4 # PODNAME: WebService::Intercom
5  
6 =pod
7  
8 =head1 NAME
9  
10 WebService::Intercom - interact with the Intercom.io API
11  
12 =head1 SYNOPSIS
13  
14 my $intercom = WebService::Intercom->new(app_id => '[APP ID]',
15 api_key => '[API KEY]');
16  
17 # Create a user
18 my $user = $intercom->user_create_or_update(
19 email => 'test@example.com',
20 name => 'test user');
21
22 # Retrieve an existing user.
23 my $existing_user = $intercom->user_get(email => 'test2@example.com');
24  
25 # Add a tag to a user
26 $user->tag('test tag');
27 $intercom->tag_create_or_update(name => "test tag");
28 $intercom->tag_items(name => "test tag", users => [{ email => 'test@example.com'}]);
29 $user->untag('test tag');
30  
31 # Change the user's name
32 $user->name = 'new name';
33 $user->save();
34  
35 # Delete the user
36 $user->delete();
37 $intercom->user_delete(email => 'test@example.com');
38  
39 # Add a note
40 $user->add_note(body => "This is a test note");
41 $intercom->note_create(email => 'test@example.com',
42 body => "This is a test note");
43
44 # Add an event
45 $user->add_event(event_name => 'test event');
46 $intercom->event_create(email => 'test@example.com',
47 event_name => 'test event',
48 metadata => {
49 "article" => {"url" => "https://example.org/",
50 "value" => "link text"},
51 });
52  
53 =head1 DESCRIPTION
54  
55 Provides a nice API for Intercom.io rather than making raw requests.
56  
57 =head1 IMPLEMENTATION PHILOSOPHY
58  
59 This module attempts to stick as close to the API as possible.
60  
61 Documentation for the v2 API:
62  
63 L<http://doc.intercom.io/api/>
64  
65 For examples see the test cases, most functionality is well exercised
66 via tests.
67  
68 =cut
69  
70  
71 2 ▶use WebService::Intercom::Exception;
Subroutine __ANON__: called CC=1 SCAR=0.0
72 2 ▶use WebService::Intercom::Types;
Subroutine __ANON__: called CC=1 SCAR=0.0
73 2 ▶use WebService::Intercom::User;
Subroutine __ANON__: called CC=1 SCAR=0.0
74 2 ▶use WebService::Intercom::Tag;
Subroutine __ANON__: called CC=1 SCAR=0.0
75 2 ▶use WebService::Intercom::Note;
Subroutine __ANON__: called CC=1 SCAR=0.0
76 2 ▶use WebService::Intercom::Message;
Subroutine __ANON__: called CC=1 SCAR=0.0
77 2 ▶use WebService::Intercom::Admin;
Subroutine __ANON__: called CC=1 SCAR=0.0
78 2  
79 2 ▶class WebService::Intercom types WebService::Intercom::Types {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=4.1
80 2 ▶ use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 2 ▶ use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 2 ▶ use HTTP::Request::Common qw(DELETE POST GET);
Subroutine BEGIN: called CC=1 SCAR=0.0
83 2 ▶ use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶ use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶ use Kavorka qw( multi method );
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87  
88 0 ▶ has 'ua' => (is => 'ro', default => sub { return LWP::UserAgent->new(keep_alive => 10, agent => "WebService::Intercom/1.0") } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
89 2 has 'app_id' => (is => 'ro');
90 2 has 'api_key' => (is => 'ro');
91  
92 2 has 'api_base' => (is => 'ro', isa => Str, default => 'https://api.intercom.io');
93  
94 =head1 FUNCTIONS
95  
96 =head2 user_get
97  
98 Retrieves an existing user.
99  
100 $intercom->user_get(Maybe[Str] :$user_id?,
101 Maybe[Str] :$email?,
102 Maybe[Str] :$id?);
103  
104 Only one of user_id, email or id are required to retrieve a user.
105  
106 Returns a L<WebService::Intercom::User>.
107  
108 =cut
109
110
111 method user_get(Maybe[Str] :$user_id?,
112 Maybe[Str] :$email?,
113 0 ▶ Maybe[Str] :$id?) {
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine user_get: not called CC=23 SCAR=56.8
Branch: 14 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'user_id'} ? : 0 0 0
if (exists $_{"user_id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($user_id) or _failed_check(81, "Maybe[Str]", $user_id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'email'} ? : 0 0 0
if (exists $_{"email"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($email) or _failed_check(81, "Maybe[Str]", $email, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'id'} ? : 0 0 0
if (exists $_{"id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($id) or _failed_check(81, "Maybe[Str]", $id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
114  
115 0 ▶ if (!(defined($user_id) xor defined($email) xor defined($id))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_id xor defined $email xor defined $id) 0 0 0
Condition0%0/8
defined $user_id xor defined $email xor defined $id
l&&rl&&!r!l&&r!l&&!r
0000
defined $user_id ^^ defined $email
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/3
defined $user_id xor defined $email xor defined $id
defined $user_id defined $email defined $id
Truth table0%0/8
A ^^ B xor C
A= defined $user_idB= defined $emailC= defined $id
ABCresult
1010
0110
1001
0101
1111
0011
1100
0000
116 0 WebService::Intercom::Exception->throw({ message => "One and only one of user_id, email or id must be defined"});
117 }
118  
119 0 my $request;
120 0 ▶ if (defined($id)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $id) { } 0 0 0
elsif (defined $user_id) { } 0 0 0
elsif (defined $email) { } 0 0 0
121 0 $request = GET($self->api_base . '/users/' . $id);
122 } elsif (defined($user_id)) {
123 0 $request = GET($self->api_base . '/users?user_id=' . URI::Escape::uri_escape($user_id));
124 } elsif (defined($email)) {
125 0 $request = GET($self->api_base . '/users?email=' . URI::Escape::uri_escape($email));
126 }
127  
128 0 $self->_request($request);
129 }
130  
131 =head2 user_create_or_update
132  
133 Creates or updates a user.
134  
135 # When you have an existing WebService::Intercom::User
136 $intercom->user_create_or_update(WebService::Intercom::User $user);
137  
138 or
139  
140 $intercom->user_create_or_update(Maybe[Str] :$user_id?,
141 Maybe[Str] :$email?,
142 Maybe[Str] :$id?,
143 Maybe[Int] :$signed_up_at?,
144 Str :$name?,
145 Maybe[IPAddressType] :$last_seen_ip?,
146 CustomAttributesType :$custom_attributes?,
147 Maybe[Str] :$last_seen_user_agent?,
148 HashRef :$companies?,
149 Maybe[Int] :$last_request_at?,
150 Maybe[Bool] :$unsubscribed_from_emails?,
151 Maybe[Bool] :$update_last_request_at?,
152 Maybe[Bool] :$new_session?);
153
154 Returns a L<WebService::Intercom::User> that represents the new or updated user.
155  
156 =cut
157  
158
159
160 0 ▶ multi method user_create_or_update(WebService::Intercom::User $user) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine user_create_or_update: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC8($user) or _failed_check(145, "InstanceOf[\"WebService::Intercom::User\"]", $user, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
161 0 return $self->user_create_or_update(user_id => $user->user_id,
162 email => $user->email,
163 id => $user->id,
164 name => $user->name,
165 last_seen_ip => $user->last_seen_ip,
166 custom_attributes => $user->custom_attributes,
167 last_seen_user_agent => $user->user_agent_data,
168 last_request_at => $user->last_request_at,
169 unsubscribed_from_emails => $user->unsubscribed_from_emails,
170 );
171 }
172  
173 multi method user_create_or_update(Maybe[Str] :$user_id?,
174 Maybe[Str] :$email?,
175 Maybe[Str] :$id?,
176 Maybe[Int] :$signed_up_at?,
177 Maybe[Str] :$name?,
178 Maybe[IPAddressType] :$last_seen_ip?,
179 CustomAttributesType :$custom_attributes?,
180 Maybe[Str] :$last_seen_user_agent?,
181 HashRef :$companies?,
182 Maybe[Int] :$last_request_at?,
183 Maybe[Bool] :$unsubscribed_from_emails?,
184 Maybe[Bool] :$update_last_request_at?,
185 0 ▶ Maybe[Bool] :$new_session?) {
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine BEGIN: called CC=1 SCAR=4.5
Subroutine user_create_or_update: not called CC=75 SCAR=81.3
Branch: 61 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'user_id'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"user_id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($user_id) or _failed_check(81, "Maybe[Str]", $user_id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'email'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"email"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($email) or _failed_check(81, "Maybe[Str]", $email, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'id'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($id) or _failed_check(81, "Maybe[Str]", $id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'signed_up_at'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"signed_up_at"}) 0 0 0
Type::Tiny::XS::AUTO::TC5($signed_up_at) or _failed_check(134, "Maybe[Int]", $signed_up_at, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'name'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"name"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($name) or _failed_check(81, "Maybe[Str]", $name, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'last_seen_ip'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"last_seen_ip"}) 0 0 0
do { not defined $last_seen_ip or do { defined $last_seen_ip and not ref $last_seen_ip and not !($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u) } } or _failed_check(139, "Maybe[IPAddressType]", $last_seen_ip, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'custom_attributes'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"custom_attributes"}) 0 0 0
do { Ref::Util::XS::is_plain_hashref($custom_attributes) and do { my $ok = 1; foreach my $v (values %{$custom_attributes;}) { $ok = 0, last unless Type::Tiny::XS::AUTO::TC3($v); } ; foreach my $k (keys %{$custom_attributes;}) { $ok = 0, last unless defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u); } ; $ok } } or _failed_check(93, "CustomAttributesType", $custom_attributes, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
unless Type::Tiny::XS::AUTO::TC3($v) 0 0 0
unless defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u) 0 0 0
exists $_{'last_seen_user_agent'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"last_seen_user_agent"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($last_seen_user_agent) or _failed_check(81, "Maybe[Str]", $last_seen_user_agent, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'companies'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"companies"}) 0 0 0
Ref::Util::XS::is_plain_hashref($companies) or _failed_check(22, "HashRef", $companies, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'last_request_at'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"last_request_at"}) 0 0 0
Type::Tiny::XS::AUTO::TC5($last_request_at) or _failed_check(134, "Maybe[Int]", $last_request_at, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'unsubscribed_from_emails'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"unsubscribed_from_emails"}) 0 0 0
Type::Tiny::XS::AUTO::TC6($unsubscribed_from_emails) or _failed_check(137, "Maybe[Bool]", $unsubscribed_from_emails, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'update_last_request_at'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"update_last_request_at"}) 0 0 0
Type::Tiny::XS::AUTO::TC6($update_last_request_at) or _failed_check(137, "Maybe[Bool]", $update_last_request_at, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'new_session'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"new_session"}) 0 0 0
Type::Tiny::XS::AUTO::TC6($new_session) or _failed_check(137, "Maybe[Bool]", $new_session, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/21
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
!defined($last_seen_ip) || do { defined $last_seen_ip and not ref $last_seen_ip and not !($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u) }
l!l&&r!l&&!r
000
defined $last_seen_ip && !ref($last_seen_ip) && !!($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u)
!ll&&!rl&&r
000
defined $last_seen_ip and not ref $last_seen_ip
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($custom_attributes) && do { my $ok = 1; foreach my $v (values %{$custom_attributes;}) { $ok = 0, last unless Type::Tiny::XS::AUTO::TC3($v); } ; foreach my $k (keys %{$custom_attributes;}) { $ok = 0, last unless defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u); } ; $ok }
!ll&&!rl&&r
000
defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u)
!ll&&!rl&&r
000
defined $k and not ref $k
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
MC/DC0%0/2
!defined($last_seen_ip) || do { defined $last_seen_ip and not ref $last_seen_ip and not !($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u) }
!defined($last_seen_ip) do { defined $last_seen_ip and not ref $last_seen_ip and not !($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u) }
MC/DC0%0/3
defined $last_seen_ip && !ref($last_seen_ip) && !!($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u)
defined $last_seen_ip not ref $last_seen_ip !!($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u)
MC/DC0%0/2
Ref::Util::XS::is_plain_hashref($custom_attributes) && do { my $ok = 1; foreach my $v (values %{$custom_attributes;}) { $ok = 0, last unless Type::Tiny::XS::AUTO::TC3($v); } ; foreach my $k (keys %{$custom_attributes;}) { $ok = 0, last unless defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u); } ; $ok }
Ref::Util::XS::is_plain_hashref($custom_attributes) do { my $ok = 1; foreach my $v (values %{$custom_attributes;}) { $ok = 0, last unless Type::Tiny::XS::AUTO::TC3($v); } ; foreach my $k (keys %{$custom_attributes;}) { $ok = 0, last unless defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u); } ; $ok }
MC/DC0%0/3
defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u)
defined $k not ref $k not !($k =~ qr/(?^u:^[^[.\$]+$)/u)
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
not(A) || B
A= !defined($last_seen_ip)B= do { defined $last_seen_ip and not ref $last_seen_ip and not !($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u) }
ABresult
1X1
011
000
Truth table0%0/4
A and not(B) && C
A= defined $last_seen_ipB= not ref $last_seen_ipC= !!($last_seen_ip =~ qr/(?^u:^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/u)
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A && B
A= Ref::Util::XS::is_plain_hashref($custom_attributes)B= do { my $ok = 1; foreach my $v (values %{$custom_attributes;}) { $ok = 0, last unless Type::Tiny::XS::AUTO::TC3($v); } ; foreach my $k (keys %{$custom_attributes;}) { $ok = 0, last unless defined $k and not ref $k and not !($k =~ qr/(?^u:^[^[.\$]+$)/u); } ; $ok }
ABresult
0X0
100
111
Truth table0%0/4
A and not(B) and C
A= defined $kB= not ref $kC= not !($k =~ qr/(?^u:^[^[.\$]+$)/u)
ABCresult
0XX0
10X0
1100
1111
186  
187 0 my $json_content = {
188 signed_up_at => $signed_up_at,
189 name => $name,
190 last_seen_ip => $last_seen_ip,
191 custom_attributes => $custom_attributes,
192 last_seen_user_agent => $last_seen_user_agent,
193 companies => $companies,
194 last_request_at => $last_request_at,
195 unsubscribed_from_emails => $unsubscribed_from_emails,
196 update_last_request_at => $update_last_request_at,
197 new_session => $new_session
198 };
199
200 0 ▶ if (defined($user_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user_id) 0 0 0
201 0 $json_content->{user_id} = $user_id;
202 }
203 0 ▶ if (defined($email)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $email) 0 0 0
204 0 $json_content->{email} = $email;
205 }
206 0 ▶ if (defined($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 0 0 0
207 0 $json_content->{id} = $id;
208 }
209  
210 0 my $json = JSON::XS::encode_json($json_content);
211 0 my $request = POST($self->api_base . '/users',
212 'Content-Type' => 'application/json',
213 Content => $json
214 );
215  
216 0 $self->_request($request);
217 }
218  
219  
220 =head2 user_delete
221  
222 Deletes a user
223  
224 # When you have an existing WebService::Intercom::User
225 $intercom->user_delete(WebService::Intercom::User $user);
226  
227 or
228  
229 $intercom->user_delete(Maybe[Str] :$user_id?,
230 Maybe[Str] :$email?,
231 Maybe[Str] :$id?);
232  
233 Only one of user_id, email or id is required.
234
235 Returns a L<WebService::Intercom::User> that represents the deleted user.
236  
237 =cut
238  
239
240 0 ▶ multi method user_delete(WebService::Intercom::User $user) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine user_delete: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC8($user) or _failed_check(145, "InstanceOf[\"WebService::Intercom::User\"]", $user, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
241 0 return $self->user_delete(user_id => $user->user_id,
242 id => $user->id,
243 email => $user->email);
244 }
245
246 multi method user_delete(Str :$user_id?,
247 Str :$id?,
248 0 ▶ Str :$email?) {
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine user_delete: not called CC=25 SCAR=58.6
Branch: 19 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'user_id'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"user_id"}) 0 0 0
Type::Tiny::XS::Str($user_id) or _failed_check(9, "Str", $user_id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'id'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"id"}) 0 0 0
Type::Tiny::XS::Str($id) or _failed_check(9, "Str", $id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'email'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"email"}) 0 0 0
Type::Tiny::XS::Str($email) or _failed_check(9, "Str", $email, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
249 0 my $request;
250 0 ▶ if (defined($id)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $id) { } 0 0 0
elsif (defined $user_id) { } 0 0 0
elsif (defined $email) { } 0 0 0
251 0 $request = DELETE($self->api_base . '/users/' . $id);
252 } elsif (defined($user_id)) {
253 0 $request = DELETE($self->api_base . '/users?user_id=' . URI::Escape::uri_escape($user_id));
254 } elsif (defined($email)) {
255 0 $request = DELETE($self->api_base . '/users?email=' . URI::Escape::uri_escape($email));
256 }
257  
258 0 $self->_request($request);
259 }
260  
261 =head2 tag_create_or_update
262  
263 Creates or updates a tag.
264  
265 # When you have an existing WebService::Intercom::User
266 $intercom->tag_create_or_update(WebService::Intercom::Tag $tag);
267  
268 or
269  
270 $intercom->tag_create_or_update(Str :$name,
271 Maybe[Str] :$id?);
272  
273 Returns a L<WebService::Intercom::Tag> that represents the tag.
274  
275 =cut
276  
277 0 ▶ multi method tag_create_or_update(WebService::Intercom::Tag $tag) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine tag_create_or_update: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC4($tag) or _failed_check(133, "InstanceOf[\"WebService::Intercom::Tag\"]", $tag, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
278 0 return $self->tag_create_or_update(name => $tag->name,
279 id => $tag->id);
280 }
281
282 multi method tag_create_or_update(Str :$name,
283 0 ▶ Maybe[Str] :$id?) {
Subroutine BEGIN: called CC=1 SCAR=3.8
Subroutine BEGIN: called CC=1 SCAR=3.8
Subroutine BEGIN: called CC=1 SCAR=3.8
Subroutine BEGIN: called CC=1 SCAR=3.8
Subroutine BEGIN: called CC=1 SCAR=3.8
Subroutine BEGIN: called CC=1 SCAR=3.8
Subroutine tag_create_or_update: not called CC=19 SCAR=52.9
Branch: 15 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'name'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"name"}) 0 0 0
Type::Tiny::XS::Str($name) or _failed_check(9, "Str", $name, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'id'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($id) or _failed_check(81, "Maybe[Str]", $id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
284 0 my $json_content = {
285 name => $name,
286 };
287 0 ▶ if (defined($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 0 0 0
288 0 $json_content->{id} = $id;
289 }
290
291 0 my $request = POST($self->api_base . '/tags',
292 'Content-Type' => 'application/json',
293 Content => JSON::XS::encode_json($json_content)
294 );
295  
296 0 return $self->_request($request);
297 }
298  
299  
300 =head2 tag_items
301  
302 Applies or removes a tag to users or companies
303  
304 # When you have an existing WebService::Intercom::User
305 $intercom->tag_items(Str :$name,
306 ArrayRef[TagUserIdentifierType] :$users?,
307 ArrayRef[TagCompanyIdentifierType] :$companies?);
308  
309 =cut
310  
311
312 method tag_items(Str :$name,
313 ArrayRef[TagUserIdentifierType] :$users?,
314 0 ▶ ArrayRef[TagCompanyIdentifierType] :$companies?) {
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine tag_items: not called CC=43 SCAR=71.7
Branch: 16 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'name'} ? : 0 0 0
if (exists $_{"name"}) 0 0 0
Type::Tiny::XS::Str($name) or _failed_check(9, "Str", $name, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'users'} ? : 0 0 0
if (exists $_{"users"}) 0 0 0
do { Ref::Util::XS::is_plain_arrayref($users) and do { my $ok = 1; foreach my $i (@{$users;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"email"} || do { Type::Tiny::XS::Str($i->{"email"}) } and !exists $i->{"user_id"} || do { Type::Tiny::XS::Str($i->{"user_id"}) } and !exists $i->{"untag"} || do { Type::Tiny::XS::Bool($i->{"untag"}) } }; } ; $ok } } or _failed_check(147, "ArrayRef[TagUserIdentifierType]", $users, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"email"} || do { Type::Tiny::XS::Str($i->{"email"}) } and !exists $i->{"user_id"} || do { Type::Tiny::XS::Str($i->{"user_id"}) } and !exists $i->{"untag"} || do { Type::Tiny::XS::Bool($i->{"untag"}) } } 0 0 0
exists $_{'companies'} ? : 0 0 0
if (exists $_{"companies"}) 0 0 0
do { Ref::Util::XS::is_plain_arrayref($companies) and do { my $ok = 1; foreach my $i (@{$companies;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"company_id"} || do { Type::Tiny::XS::Str($i->{"company_id"}) } and !exists $i->{"untag"} || do { Type::Tiny::XS::Bool($i->{"untag"}) } }; } ; $ok } } or _failed_check(148, "ArrayRef[TagCompanyIdentifierType]", $companies, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"company_id"} || do { Type::Tiny::XS::Str($i->{"company_id"}) } and !exists $i->{"untag"} || do { Type::Tiny::XS::Bool($i->{"untag"}) } } 0 0 0
Condition0%0/57
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_arrayref($users) && do { my $ok = 1; foreach my $i (@{$users;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'email'} || do { Type::Tiny::XS::Str($i->{'email'}) } and !exists $i->{'user_id'} || do { Type::Tiny::XS::Str($i->{'user_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) && !grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) && (!exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) }) && (!exists $i->{'email'} || do { Type::Tiny::XS::Str($i->{'email'}) }) && (!exists $i->{'user_id'} || do { Type::Tiny::XS::Str($i->{'user_id'}) }) && (!exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) })
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"email"} || do { Type::Tiny::XS::Str($i->{"email"}) } and !exists $i->{"user_id"} || do { Type::Tiny::XS::Str($i->{"user_id"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"email"} || do { Type::Tiny::XS::Str($i->{"email"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;})
!ll&&!rl&&r
000
not exists $i->{"id"} or do { Type::Tiny::XS::Str($i->{"id"}) }
l!l&&r!l&&!r
000
not exists $i->{"email"} or do { Type::Tiny::XS::Str($i->{"email"}) }
l!l&&r!l&&!r
000
not exists $i->{"user_id"} or do { Type::Tiny::XS::Str($i->{"user_id"}) }
l!l&&r!l&&!r
000
not exists $i->{"untag"} or do { Type::Tiny::XS::Bool($i->{"untag"}) }
l!l&&r!l&&!r
000
Ref::Util::XS::is_plain_arrayref($companies) && do { my $ok = 1; foreach my $i (@{$companies;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'company_id'} || do { Type::Tiny::XS::Str($i->{'company_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) && !grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) && (!exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) }) && (!exists $i->{'company_id'} || do { Type::Tiny::XS::Str($i->{'company_id'}) }) && (!exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) })
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) } and !exists $i->{"company_id"} || do { Type::Tiny::XS::Str($i->{"company_id"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{"id"} || do { Type::Tiny::XS::Str($i->{"id"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;})
!ll&&!rl&&r
000
not exists $i->{"id"} or do { Type::Tiny::XS::Str($i->{"id"}) }
l!l&&r!l&&!r
000
not exists $i->{"company_id"} or do { Type::Tiny::XS::Str($i->{"company_id"}) }
l!l&&r!l&&!r
000
not exists $i->{"untag"} or do { Type::Tiny::XS::Bool($i->{"untag"}) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
MC/DC0%0/2
Ref::Util::XS::is_plain_arrayref($users) && do { my $ok = 1; foreach my $i (@{$users;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'email'} || do { Type::Tiny::XS::Str($i->{'email'}) } and !exists $i->{'user_id'} || do { Type::Tiny::XS::Str($i->{'user_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
Ref::Util::XS::is_plain_arrayref($users) do { my $ok = 1; foreach my $i (@{$users;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'email'} || do { Type::Tiny::XS::Str($i->{'email'}) } and !exists $i->{'user_id'} || do { Type::Tiny::XS::Str($i->{'user_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
MC/DC0%0/10
Ref::Util::XS::is_plain_hashref($i) && !grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) && (!exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) }) && (!exists $i->{'email'} || do { Type::Tiny::XS::Str($i->{'email'}) }) && (!exists $i->{'user_id'} || do { Type::Tiny::XS::Str($i->{'user_id'}) }) && (!exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) })
Ref::Util::XS::is_plain_hashref($i) not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) not exists $i->{"id"} do { Type::Tiny::XS::Str($i->{"id"}) } not exists $i->{"email"} do { Type::Tiny::XS::Str($i->{"email"}) } not exists $i->{"user_id"} do { Type::Tiny::XS::Str($i->{"user_id"}) } not exists $i->{"untag"} do { Type::Tiny::XS::Bool($i->{"untag"}) }
MC/DC0%0/2
Ref::Util::XS::is_plain_arrayref($companies) && do { my $ok = 1; foreach my $i (@{$companies;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'company_id'} || do { Type::Tiny::XS::Str($i->{'company_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
Ref::Util::XS::is_plain_arrayref($companies) do { my $ok = 1; foreach my $i (@{$companies;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'company_id'} || do { Type::Tiny::XS::Str($i->{'company_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
MC/DC0%0/8
Ref::Util::XS::is_plain_hashref($i) && !grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) && (!exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) }) && (!exists $i->{'company_id'} || do { Type::Tiny::XS::Str($i->{'company_id'}) }) && (!exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) })
Ref::Util::XS::is_plain_hashref($i) not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) not exists $i->{"id"} do { Type::Tiny::XS::Str($i->{"id"}) } not exists $i->{"company_id"} do { Type::Tiny::XS::Str($i->{"company_id"}) } not exists $i->{"untag"} do { Type::Tiny::XS::Bool($i->{"untag"}) }
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= Ref::Util::XS::is_plain_arrayref($users)B= do { my $ok = 1; foreach my $i (@{$users;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'email'} || do { Type::Tiny::XS::Str($i->{'email'}) } and !exists $i->{'user_id'} || do { Type::Tiny::XS::Str($i->{'user_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
ABresult
0X0
100
111
Truth table0%0/33
A and not(B) and not(C) or D and not(E) or F and not(G) or H && not(I) or J
A= Ref::Util::XS::is_plain_hashref($i)B= not grep((!/\A(?:id|email|user_id|untag)\z/u), keys %{$i;})C= not exists $i->{"id"}D= do { Type::Tiny::XS::Str($i->{"id"}) }E= not exists $i->{"email"}F= do { Type::Tiny::XS::Str($i->{"email"}) }G= not exists $i->{"user_id"}H= do { Type::Tiny::XS::Str($i->{"user_id"}) }I= not exists $i->{"untag"}J= do { Type::Tiny::XS::Bool($i->{"untag"}) }
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
1100XXXXXX0
111X00XXXX0
110100XXXX0
111X1X00XX0
111X0100XX0
11011X00XX0
11010100XX0
111X1X1X000
111X1X01000
111X011X000
111X0101000
11011X1X000
11011X01000
1101011X000
11010101000
111X1X1X1X1
111X1X1X011
111X1X011X1
111X1X01011
111X011X1X1
111X011X011
111X01011X1
111X0101011
11011X1X1X1
11011X1X011
11011X011X1
11011X01011
1101011X1X1
1101011X011
110101011X1
11010101011
Truth table0%0/3
A && B
A= Ref::Util::XS::is_plain_arrayref($companies)B= do { my $ok = 1; foreach my $i (@{$companies;}) { $ok = 0, last unless do { Ref::Util::XS::is_plain_hashref($i) and not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;}) and !exists $i->{'id'} || do { Type::Tiny::XS::Str($i->{'id'}) } and !exists $i->{'company_id'} || do { Type::Tiny::XS::Str($i->{'company_id'}) } and !exists $i->{'untag'} || do { Type::Tiny::XS::Bool($i->{'untag'}) } }; } ; $ok }
ABresult
0X0
100
111
Truth table0%0/17
A and not(B) and not(C) or D and not(E) or F && not(G) or H
A= Ref::Util::XS::is_plain_hashref($i)B= not grep((!/\A(?:id|company_id|untag)\z/u), keys %{$i;})C= not exists $i->{"id"}D= do { Type::Tiny::XS::Str($i->{"id"}) }E= not exists $i->{"company_id"}F= do { Type::Tiny::XS::Str($i->{"company_id"}) }G= not exists $i->{"untag"}H= do { Type::Tiny::XS::Bool($i->{"untag"}) }
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
1100XXXX0
111X00XX0
110100XX0
111X1X000
111X01000
11011X000
110101000
111X1X1X1
111X1X011
111X011X1
111X01011
11011X1X1
11011X011
1101011X1
110101011
315
316 0 my $json_content = {
317 name => $name,
318 };
319  
320 0 ▶ if (!(defined($users) xor defined($companies))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $users xor defined $companies) 0 0 0
Condition0%0/4
defined $users xor defined $companies
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
defined $users xor defined $companies
defined $users defined $companies
Truth table0%0/4
A xor B
A= defined $usersB= defined $companies
ABresult
110
101
011
000
321 0 WebService::Intercom::Exception->throw({ message => "Either users or companies must be defined as a parameter, not both and not neither"});
322 }
323  
324 0 ▶ if (defined($users)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $users) { } 0 0 0
elsif (defined $companies) { } 0 0 0
325 0 $json_content->{users} = $users;
326 } elsif (defined($companies)) {
327 0 $json_content->{companies} = $companies;
328 }
329
330
331 0 my $request = POST($self->api_base . '/tags',
332 'Content-Type' => 'application/json',
333 Content => JSON::XS::encode_json($json_content)
334 );
335  
336 0 return $self->_request($request);
337 }
338  
339  
340 =head2 tag_delete
341  
342 Deletes a tag
343  
344 # When you have an existing WebService::Intercom::User
345 $intercom->tag_delete(WebService::Intercom::Tag $tag);
346  
347 or
348  
349 $intercom->tag_delete(Str :$id);
350  
351 Returns undef
352  
353 =cut
354  
355
356 0 ▶ multi method tag_delete(Str :$id) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine tag_delete: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'id'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"id"}) 0 0 0
Type::Tiny::XS::Str($id) or _failed_check(9, "Str", $id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
357 0 $self->_request(DELETE($self->api_base . '/tags/' . $id), no_content => 1);
358 }
359  
360 0 ▶ multi method tag_delete(WebService::Intercom::Tag $tag) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine tag_delete: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC4($tag) or _failed_check(133, "InstanceOf[\"WebService::Intercom::Tag\"]", $tag, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
361 0 return $self->tag_delete(id => $tag->id);
362 }
363  
364  
365 =head2 note_create
366  
367 Creates a note for a user
368  
369 # When you have an existing WebService::Intercom::User
370 $intercom->note_create(Maybe[Str] :$user_id?,
371 Maybe[Str] :$email?,
372 Maybe[Str] :$id?,
373 Maybe[Str] :$admin_id?,
374 Str :$body);
375  
376 Returns a L<WebService::Intercom::Note> that represents the note.
377  
378 =cut
379  
380
381  
382 method note_create(Maybe[Str] :$user_id?,
383 Maybe[Str] :$email?,
384 Maybe[Str] :$id?,
385 Maybe[Str] :$admin_id?,
386 0 ▶ Str :$body) {
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine note_create: not called CC=29 SCAR=61.2
Branch: 20 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'user_id'} ? : 0 0 0
if (exists $_{"user_id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($user_id) or _failed_check(81, "Maybe[Str]", $user_id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'email'} ? : 0 0 0
if (exists $_{"email"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($email) or _failed_check(81, "Maybe[Str]", $email, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'id'} ? : 0 0 0
if (exists $_{"id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($id) or _failed_check(81, "Maybe[Str]", $id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'admin_id'} ? : 0 0 0
if (exists $_{"admin_id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($admin_id) or _failed_check(81, "Maybe[Str]", $admin_id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'body'} ? : 0 0 0
if (exists $_{"body"}) 0 0 0
Type::Tiny::XS::Str($body) or _failed_check(9, "Str", $body, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
387 0 ▶ if (!(defined($user_id) xor defined($email) xor defined($id))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_id xor defined $email xor defined $id) 0 0 0
Condition0%0/8
defined $user_id xor defined $email xor defined $id
l&&rl&&!r!l&&r!l&&!r
0000
defined $user_id ^^ defined $email
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/3
defined $user_id xor defined $email xor defined $id
defined $user_id defined $email defined $id
Truth table0%0/8
A ^^ B xor C
A= defined $user_idB= defined $emailC= defined $id
ABCresult
1010
0110
1001
0101
1111
0011
1100
0000
388 0 WebService::Intercom::Exception->throw({ message => "One and only one of user_id, email or id must be defined"});
389 }
390  
391 0 my $json_content = {
392 body => $body,
393 };
394  
395 0 ▶ if (defined($user_id)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $user_id) { } 0 0 0
elsif (defined $email) { } 0 0 0
elsif (defined $id) { } 0 0 0
396 0 $json_content->{user}->{user_id} = $user_id;
397 } elsif (defined($email)) {
398 0 $json_content->{user}->{email} = $email;
399 } elsif (defined($id)) {
400 0 $json_content->{user}->{id} = $id;
401 }
402  
403 0 my $request = POST($self->api_base . '/notes',
404 'Content-Type' => 'application/json',
405 Content => JSON::XS::encode_json($json_content)
406 );
407  
408  
409 0 return $self->_request($request);
410 }
411  
412 =head2 event_create
413  
414 Creates an event for a user
415  
416 # When you have an existing WebService::Intercom::User
417 $intercom->event_create(Maybe[Str] :$user_id?,
418 Maybe[Str] :$email?,
419 EventNameType :$event_name,
420 Maybe[Int] :$created_at?,
421 Maybe[EventMetadataType] :$metadata?);
422  
423 Returns undef.
424  
425 =cut
426
427 method event_create(Maybe[Str] :$user_id?,
428 Maybe[Str] :$email?,
429 EventNameType :$event_name,
430 Maybe[Int] :$created_at?,
431 0 ▶ Maybe[EventMetadataType] :$metadata? where { !defined($_) || scalar(keys %$_) <= 5 }) {
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine BEGIN: called CC=1 SCAR=4.8
Subroutine event_create: not called CC=50 SCAR=74.3
Branch: 23 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'user_id'} ? : 0 0 0
if (exists $_{"user_id"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($user_id) or _failed_check(81, "Maybe[Str]", $user_id, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'email'} ? : 0 0 0
if (exists $_{"email"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($email) or _failed_check(81, "Maybe[Str]", $email, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'event_name'} ? : 0 0 0
if (exists $_{"event_name"}) 0 0 0
defined $event_name and not ref $event_name and not !($event_name =~ qr/(?^u:^[^[.\$]+$)/u) or _failed_check(100, "EventNameType", $event_name, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'created_at'} ? : 0 0 0
if (exists $_{"created_at"}) 0 0 0
Type::Tiny::XS::AUTO::TC5($created_at) or _failed_check(134, "Maybe[Int]", $created_at, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'metadata'} ? : 0 0 0
if (exists $_{"metadata"}) 0 0 0
do { not defined $metadata or do { Ref::Util::XS::is_plain_hashref($metadata) and do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"} and do { Type::Tiny::XS::Str($v->{"currency"}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok } } } or _failed_check(149, "Maybe[EventMetadataType]", $metadata, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"} and do { Type::Tiny::XS::Str($v->{"currency"}) } } 0 0 0
unless Type::Tiny::XS::Str($k) 0 0 0
do { local $_ = $metadata; $Kavorka::Parameter::PARAMS[66]{"constraints"}[0]->() } or Carp::croak("\$metadata failed value constraint") 0 0 0
Condition0%0/54
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
defined $event_name and not ref $event_name and not !($event_name =~ qr/(?^u:^[^[.\$]+$)/u)
!ll&&!rl&&r
000
defined $event_name and not ref $event_name
!ll&&!rl&&r
000
!defined($metadata) || do { Ref::Util::XS::is_plain_hashref($metadata) and do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok } }
l!l&&r!l&&!r
000
Ref::Util::XS::is_plain_hashref($metadata) && do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok }
!ll&&!rl&&r
000
defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"} and do { Type::Tiny::XS::Str($v->{"currency"}) } }
l!l&&r!l&&!r
000
defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } }
l!l&&r!l&&!r
000
defined $v and not ref $v
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) && !grep((!/\A(?:url|value)\z/u), keys %{$v;}) && exists $v->{'url'} && do { Type::Tiny::XS::Str($v->{'url'}) } && (!exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) })
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"}
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;})
!ll&&!rl&&r
000
not exists $v->{"value"} or do { Type::Tiny::XS::Str($v->{"value"}) }
l!l&&r!l&&!r
000
Ref::Util::XS::is_plain_hashref($v) && !grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) && exists $v->{'amount'} && do { Type::Tiny::XS::Int($v->{'amount'}) } && exists $v->{'currency'} && do { Type::Tiny::XS::Str($v->{'currency'}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"}
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"}
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;})
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
MC/DC0%0/3
defined $event_name and not ref $event_name and not !($event_name =~ qr/(?^u:^[^[.\$]+$)/u)
defined $event_name not ref $event_name not !($event_name =~ qr/(?^u:^[^[.\$]+$)/u)
MC/DC0%0/2
!defined($metadata) || do { Ref::Util::XS::is_plain_hashref($metadata) and do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok } }
!defined($metadata) do { Ref::Util::XS::is_plain_hashref($metadata) and do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok } }
MC/DC0%0/2
Ref::Util::XS::is_plain_hashref($metadata) && do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok }
Ref::Util::XS::is_plain_hashref($metadata) do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok }
MC/DC0%0/4
defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"} and do { Type::Tiny::XS::Str($v->{"currency"}) } }
defined $v not ref $v do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } } do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"} and do { Type::Tiny::XS::Str($v->{"currency"}) } }
MC/DC0%0/6
Ref::Util::XS::is_plain_hashref($v) && !grep((!/\A(?:url|value)\z/u), keys %{$v;}) && exists $v->{'url'} && do { Type::Tiny::XS::Str($v->{'url'}) } && (!exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) })
Ref::Util::XS::is_plain_hashref($v) not grep((!/\A(?:url|value)\z/u), keys %{$v;}) exists $v->{"url"} do { Type::Tiny::XS::Str($v->{"url"}) } not exists $v->{"value"} do { Type::Tiny::XS::Str($v->{"value"}) }
MC/DC0%0/6
Ref::Util::XS::is_plain_hashref($v) && !grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) && exists $v->{'amount'} && do { Type::Tiny::XS::Int($v->{'amount'}) } && exists $v->{'currency'} && do { Type::Tiny::XS::Str($v->{'currency'}) }
Ref::Util::XS::is_plain_hashref($v) not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) exists $v->{"amount"} do { Type::Tiny::XS::Int($v->{"amount"}) } exists $v->{"currency"} do { Type::Tiny::XS::Str($v->{'currency'}) }
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/4
A and not(B) and C
A= defined $event_nameB= not ref $event_nameC= not !($event_name =~ qr/(?^u:^[^[.\$]+$)/u)
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
not(A) || B
A= !defined($metadata)B= do { Ref::Util::XS::is_plain_hashref($metadata) and do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok } }
ABresult
1X1
011
000
Truth table0%0/3
A && B
A= Ref::Util::XS::is_plain_hashref($metadata)B= do { my $ok = 1; foreach my $v (values %{$metadata;}) { $ok = 0, last unless defined $v and not ref $v or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{'url'} and do { Type::Tiny::XS::Str($v->{'url'}) } and !exists $v->{'value'} || do { Type::Tiny::XS::Str($v->{'value'}) } } or do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{'amount'} and do { Type::Tiny::XS::Int($v->{'amount'}) } and exists $v->{'currency'} and do { Type::Tiny::XS::Str($v->{'currency'}) } }; } ; foreach my $k (keys %{$metadata;}) { $ok = 0, last unless Type::Tiny::XS::Str($k); } ; $ok }
ABresult
0X0
100
111
Truth table0%0/7
A and not(B) or C or D
A= defined $vB= not ref $vC= do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:url|value)\z/u), keys %{$v;}) and exists $v->{"url"} and do { Type::Tiny::XS::Str($v->{"url"}) } and !exists $v->{"value"} || do { Type::Tiny::XS::Str($v->{"value"}) } }D= do { Ref::Util::XS::is_plain_hashref($v) and not grep((!/\A(?:amount|currency)\z/u), keys %{$v;}) and exists $v->{"amount"} and do { Type::Tiny::XS::Int($v->{"amount"}) } and exists $v->{"currency"} and do { Type::Tiny::XS::Str($v->{"currency"}) } }
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
Truth table0%0/7
A and not(B) and C and D && not(E) or F
A= Ref::Util::XS::is_plain_hashref($v)B= not grep((!/\A(?:url|value)\z/u), keys %{$v;})C= exists $v->{"url"}D= do { Type::Tiny::XS::Str($v->{"url"}) }E= not exists $v->{"value"}F= do { Type::Tiny::XS::Str($v->{"value"}) }
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
1111000
11111X1
1111011
Truth table0%0/7
A and not(B) and C and D and E && F
A= Ref::Util::XS::is_plain_hashref($v)B= not grep((!/\A(?:amount|currency)\z/u), keys %{$v;})C= exists $v->{"amount"}D= do { Type::Tiny::XS::Int($v->{"amount"}) }E= exists $v->{"currency"}F= do { Type::Tiny::XS::Str($v->{'currency'}) }
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
432  
433 0 ▶ if (!(defined($user_id) || defined($email))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_id or defined $email) 0 0 0
Condition0%0/3
defined $user_id or defined $email
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $user_id or defined $email
defined $user_id defined $email
Truth table0%0/3
A or B
A= defined $user_idB= defined $email
ABresult
1X1
011
000
434 0 WebService::Intercom::Exception->throw({ message => "One of user_id or email must be defined"});
435 }
436  
437 0 my $json_content = {
438 event_name => $event_name,
439 created_at => $created_at,
440 };
441  
442 0 ▶ if (defined($user_id)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $user_id) { } 0 0 0
elsif (defined $email) { } 0 0 0
443 0 $json_content->{user_id} = $user_id;
444 } elsif (defined($email)) {
445 0 $json_content->{email} = $email;
446 }
447  
448 0 ▶ if (defined($metadata)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $metadata) 0 0 0
449 0 $json_content->{metadata} = $metadata;
450 }
451
452  
453 0 my $request = POST($self->api_base . '/events',
454 'Content-Type' => 'application/json',
455 Content => JSON::XS::encode_json($json_content)
456 );
457  
458 0 return $self->_request($request, no_content => 1);
459 }
460  
461  
462 =head2 create_message
463  
464 Create a message, can be user or admin initiated.
465  
466 # When you have an existing WebService::Intercom::User
467 $intercom->create_message(MessagePersonType :$from,
468 Maybe[MessagePersonType] :$to,
469 Str :$body,
470 Maybe[Str] :$subject?,
471 Maybe[StrMatch[qr/^(plain|personal)$/]] :$template,
472 StrMatch[qr/^(inapp|email)$/] :$message_type);
473  
474 Returns a L<WebService::Intercom::Message>.
475  
476 =cut
477
478 method create_message(MessagePersonType :$from,
479 Maybe[MessagePersonType] :$to,
480 Str :$body,
481 Maybe[Str] :$subject?,
482 Maybe[StrMatch[qr/^(plain|personal)$/]] :$template,
483 0 ▶ StrMatch[qr/^(inapp|email)$/] :$message_type) {
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine create_message: not called CC=61 SCAR=78.4
Branch: 23 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'from'} ? : 0 0 0
if (exists $_{"from"}) 0 0 0
do { Ref::Util::XS::is_plain_hashref($from) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) and exists $from->{"type"} and do { defined $from->{"type"} and not ref $from->{"type"} and not !($from->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $from->{"user_id"} || do { Type::Tiny::XS::Str($from->{"user_id"}) } and !exists $from->{"email"} || do { Type::Tiny::XS::Str($from->{"email"}) } and !exists $from->{"id"} || do { Type::Tiny::XS::Str($from->{"id"}) } } or _failed_check(85, "MessagePersonType", $from, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'to'} ? : 0 0 0
if (exists $_{"to"}) 0 0 0
do { not defined $to or do { Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{"type"} and do { defined $to->{"type"} and not ref $to->{"type"} and not !($to->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{"user_id"} || do { Type::Tiny::XS::Str($to->{"user_id"}) } and !exists $to->{"email"} || do { Type::Tiny::XS::Str($to->{"email"}) } and !exists $to->{"id"} || do { Type::Tiny::XS::Str($to->{"id"}) } } } or _failed_check(150, "Maybe[MessagePersonType]", $to, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'body'} ? : 0 0 0
if (exists $_{"body"}) 0 0 0
Type::Tiny::XS::Str($body) or _failed_check(9, "Str", $body, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'subject'} ? : 0 0 0
if (exists $_{"subject"}) 0 0 0
Type::Tiny::XS::AUTO::TC2($subject) or _failed_check(81, "Maybe[Str]", $subject, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'template'} ? : 0 0 0
if (exists $_{"template"}) 0 0 0
not defined $template or defined $template and not ref $template and not !($template =~ qr/(?^:^(plain|personal)$)/u) or _failed_check(152, "Maybe[StrMatch[(?^:^(plain|personal)\$)]]", $template, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'message_type'} ? : 0 0 0
if (exists $_{"message_type"}) 0 0 0
defined $message_type and not ref $message_type and not !($message_type =~ qr/(?^:^(inapp|email)$)/u) or _failed_check(153, "StrMatch[(?^:^(inapp|email)\$)]", $message_type, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/87
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($from) && !grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) && exists $from->{'type'} && do { defined $from->{'type'} and not ref $from->{'type'} and not !($from->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } && (!exists $from->{'user_id'} || do { Type::Tiny::XS::Str($from->{'user_id'}) }) && (!exists $from->{'email'} || do { Type::Tiny::XS::Str($from->{'email'}) }) && (!exists $from->{'id'} || do { Type::Tiny::XS::Str($from->{'id'}) })
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($from) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) and exists $from->{"type"} and do { defined $from->{"type"} and not ref $from->{"type"} and not !($from->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $from->{"user_id"} || do { Type::Tiny::XS::Str($from->{"user_id"}) } and !exists $from->{"email"} || do { Type::Tiny::XS::Str($from->{"email"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($from) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) and exists $from->{"type"} and do { defined $from->{"type"} and not ref $from->{"type"} and not !($from->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $from->{"user_id"} || do { Type::Tiny::XS::Str($from->{"user_id"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($from) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) and exists $from->{"type"} and do { defined $from->{"type"} and not ref $from->{"type"} and not !($from->{"type"} =~ qr/(?^u:^(admin|user)$)/u) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($from) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) and exists $from->{"type"}
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($from) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;})
!ll&&!rl&&r
000
defined $from->{'type'} && !ref($from->{'type'}) && !!($from->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
!ll&&!rl&&r
000
defined $from->{"type"} and not ref $from->{"type"}
!ll&&!rl&&r
000
not exists $from->{"user_id"} or do { Type::Tiny::XS::Str($from->{"user_id"}) }
l!l&&r!l&&!r
000
not exists $from->{"email"} or do { Type::Tiny::XS::Str($from->{"email"}) }
l!l&&r!l&&!r
000
not exists $from->{"id"} or do { Type::Tiny::XS::Str($from->{"id"}) }
l!l&&r!l&&!r
000
!defined($to) || do { Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{'type'} and do { defined $to->{'type'} and not ref $to->{'type'} and not !($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{'user_id'} || do { Type::Tiny::XS::Str($to->{'user_id'}) } and !exists $to->{'email'} || do { Type::Tiny::XS::Str($to->{'email'}) } and !exists $to->{'id'} || do { Type::Tiny::XS::Str($to->{'id'}) } }
l!l&&r!l&&!r
000
Ref::Util::XS::is_plain_hashref($to) && !grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) && exists $to->{'type'} && do { defined $to->{'type'} and not ref $to->{'type'} and not !($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } && (!exists $to->{'user_id'} || do { Type::Tiny::XS::Str($to->{'user_id'}) }) && (!exists $to->{'email'} || do { Type::Tiny::XS::Str($to->{'email'}) }) && (!exists $to->{'id'} || do { Type::Tiny::XS::Str($to->{'id'}) })
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{"type"} and do { defined $to->{"type"} and not ref $to->{"type"} and not !($to->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{"user_id"} || do { Type::Tiny::XS::Str($to->{"user_id"}) } and !exists $to->{"email"} || do { Type::Tiny::XS::Str($to->{"email"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{"type"} and do { defined $to->{"type"} and not ref $to->{"type"} and not !($to->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{"user_id"} || do { Type::Tiny::XS::Str($to->{"user_id"}) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{"type"} and do { defined $to->{"type"} and not ref $to->{"type"} and not !($to->{"type"} =~ qr/(?^u:^(admin|user)$)/u) }
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{"type"}
!ll&&!rl&&r
000
Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;})
!ll&&!rl&&r
000
defined $to->{'type'} && !ref($to->{'type'}) && !!($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
!ll&&!rl&&r
000
defined $to->{"type"} and not ref $to->{"type"}
!ll&&!rl&&r
000
not exists $to->{"user_id"} or do { Type::Tiny::XS::Str($to->{"user_id"}) }
l!l&&r!l&&!r
000
not exists $to->{"email"} or do { Type::Tiny::XS::Str($to->{"email"}) }
l!l&&r!l&&!r
000
not exists $to->{"id"} or do { Type::Tiny::XS::Str($to->{"id"}) }
l!l&&r!l&&!r
000
not defined $template or defined $template and not ref $template and not !($template =~ qr/(?^:^(plain|personal)$)/u)
l!l&&r!l&&!r
000
defined $template and not ref $template and not !($template =~ qr/(?^:^(plain|personal)$)/u)
!ll&&!rl&&r
000
defined $template and not ref $template
!ll&&!rl&&r
000
defined $message_type and not ref $message_type and not !($message_type =~ qr/(?^:^(inapp|email)$)/u)
!ll&&!rl&&r
000
defined $message_type and not ref $message_type
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
MC/DC0%0/10
Ref::Util::XS::is_plain_hashref($from) && !grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) && exists $from->{'type'} && do { defined $from->{'type'} and not ref $from->{'type'} and not !($from->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } && (!exists $from->{'user_id'} || do { Type::Tiny::XS::Str($from->{'user_id'}) }) && (!exists $from->{'email'} || do { Type::Tiny::XS::Str($from->{'email'}) }) && (!exists $from->{'id'} || do { Type::Tiny::XS::Str($from->{'id'}) })
Ref::Util::XS::is_plain_hashref($from) not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;}) exists $from->{"type"} do { defined $from->{"type"} and not ref $from->{"type"} and not !($from->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } not exists $from->{"user_id"} do { Type::Tiny::XS::Str($from->{"user_id"}) } not exists $from->{"email"} do { Type::Tiny::XS::Str($from->{"email"}) } not exists $from->{"id"} do { Type::Tiny::XS::Str($from->{"id"}) }
MC/DC0%0/3
defined $from->{'type'} && !ref($from->{'type'}) && !!($from->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
defined $from->{"type"} not ref $from->{"type"} !!($from->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
MC/DC0%0/2
!defined($to) || do { Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{'type'} and do { defined $to->{'type'} and not ref $to->{'type'} and not !($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{'user_id'} || do { Type::Tiny::XS::Str($to->{'user_id'}) } and !exists $to->{'email'} || do { Type::Tiny::XS::Str($to->{'email'}) } and !exists $to->{'id'} || do { Type::Tiny::XS::Str($to->{'id'}) } }
!defined($to) do { Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{'type'} and do { defined $to->{'type'} and not ref $to->{'type'} and not !($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{'user_id'} || do { Type::Tiny::XS::Str($to->{'user_id'}) } and !exists $to->{'email'} || do { Type::Tiny::XS::Str($to->{'email'}) } and !exists $to->{'id'} || do { Type::Tiny::XS::Str($to->{'id'}) } }
MC/DC0%0/10
Ref::Util::XS::is_plain_hashref($to) && !grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) && exists $to->{'type'} && do { defined $to->{'type'} and not ref $to->{'type'} and not !($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } && (!exists $to->{'user_id'} || do { Type::Tiny::XS::Str($to->{'user_id'}) }) && (!exists $to->{'email'} || do { Type::Tiny::XS::Str($to->{'email'}) }) && (!exists $to->{'id'} || do { Type::Tiny::XS::Str($to->{'id'}) })
Ref::Util::XS::is_plain_hashref($to) not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) exists $to->{"type"} do { defined $to->{"type"} and not ref $to->{"type"} and not !($to->{"type"} =~ qr/(?^u:^(admin|user)$)/u) } not exists $to->{"user_id"} do { Type::Tiny::XS::Str($to->{"user_id"}) } not exists $to->{"email"} do { Type::Tiny::XS::Str($to->{"email"}) } not exists $to->{"id"} do { Type::Tiny::XS::Str($to->{"id"}) }
MC/DC0%0/3
defined $to->{'type'} && !ref($to->{'type'}) && !!($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
defined $to->{"type"} not ref $to->{"type"} !!($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
MC/DC0%0/4
not defined $template or defined $template and not ref $template and not !($template =~ qr/(?^:^(plain|personal)$)/u)
not defined $template defined $template not ref $template not !($template =~ qr/(?^:^(plain|personal)$)/u)
MC/DC0%0/3
defined $message_type and not ref $message_type and not !($message_type =~ qr/(?^:^(inapp|email)$)/u)
defined $message_type not ref $message_type not !($message_type =~ qr/(?^:^(inapp|email)$)/u)
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/19
A and not(B) and C and D and not(E) or F and not(G) or H && not(I) or J
A= Ref::Util::XS::is_plain_hashref($from)B= not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$from;})C= exists $from->{"type"}D= do { defined $from->{"type"} and not ref $from->{"type"} and not !($from->{"type"} =~ qr/(?^u:^(admin|user)$)/u) }E= not exists $from->{"user_id"}F= do { Type::Tiny::XS::Str($from->{"user_id"}) }G= not exists $from->{"email"}H= do { Type::Tiny::XS::Str($from->{"email"}) }I= not exists $from->{"id"}J= do { Type::Tiny::XS::Str($from->{"id"}) }
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
110XXXXXXX0
1110XXXXXX0
111100XXXX0
11111X00XX0
11110100XX0
11111X1X000
11111X01000
1111011X000
11110101000
11111X1X1X1
11111X1X011
11111X011X1
11111X01011
1111011X1X1
1111011X011
111101011X1
11110101011
Truth table0%0/4
A and not(B) && C
A= defined $from->{"type"}B= not ref $from->{"type"}C= !!($from->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
not(A) || B
A= !defined($to)B= do { Ref::Util::XS::is_plain_hashref($to) and not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;}) and exists $to->{'type'} and do { defined $to->{'type'} and not ref $to->{'type'} and not !($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u) } and !exists $to->{'user_id'} || do { Type::Tiny::XS::Str($to->{'user_id'}) } and !exists $to->{'email'} || do { Type::Tiny::XS::Str($to->{'email'}) } and !exists $to->{'id'} || do { Type::Tiny::XS::Str($to->{'id'}) } }
ABresult
1X1
011
000
Truth table0%0/19
A and not(B) and C and D and not(E) or F and not(G) or H && not(I) or J
A= Ref::Util::XS::is_plain_hashref($to)B= not grep((!/\A(?:type|user_id|email|id)\z/u), keys %{$to;})C= exists $to->{"type"}D= do { defined $to->{"type"} and not ref $to->{"type"} and not !($to->{"type"} =~ qr/(?^u:^(admin|user)$)/u) }E= not exists $to->{"user_id"}F= do { Type::Tiny::XS::Str($to->{"user_id"}) }G= not exists $to->{"email"}H= do { Type::Tiny::XS::Str($to->{"email"}) }I= not exists $to->{"id"}J= do { Type::Tiny::XS::Str($to->{"id"}) }
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
110XXXXXXX0
1110XXXXXX0
111100XXXX0
11111X00XX0
11110100XX0
11111X1X000
11111X01000
1111011X000
11110101000
11111X1X1X1
11111X1X011
11111X011X1
11111X01011
1111011X1X1
1111011X011
111101011X1
11110101011
Truth table0%0/4
A and not(B) && C
A= defined $to->{"type"}B= not ref $to->{"type"}C= !!($to->{'type'} =~ qr/(?^u:^(admin|user)$)/u)
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/5
not(A) or B and not(C) and D
A= not defined $templateB= defined $templateC= not ref $templateD= not !($template =~ qr/(?^:^(plain|personal)$)/u)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
Truth table0%0/4
A and not(B) and C
A= defined $message_typeB= not ref $message_typeC= not !($message_type =~ qr/(?^:^(inapp|email)$)/u)
ABCresult
0XX0
10X0
1100
1111
484  
485 0 ▶ if (defined($message_type) && $message_type eq 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message_type and $message_type eq "email") 0 0 0
Condition0%0/3
defined $message_type and $message_type eq "email"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $message_type and $message_type eq "email"
defined $message_type $message_type eq "email"
Truth table0%0/3
A and B
A= defined $message_typeB= $message_type eq "email"
ABresult
0X0
100
111
486 0 ▶ defined($subject) || WebService::Intercom::Exception->throw({ message => "Subject is required for email message"});
Branch: 1 branch
BranchTrueFalseTotal
defined $subject or "WebService::Intercom::Exception"->throw({"message", "Subject is required for email message"}) 0 0 0
487 }
488
489 0 ▶ my $json_content = {
Branch: 4 branches
BranchTrueFalseTotal
defined $to ? : 0 0 0
defined $subject ? : 0 0 0
defined $template ? : 0 0 0
defined $message_type ? : 0 0 0
490 from => $from,
491 (defined($to) ? (to => $to) : ()),
492 (defined($subject) ? (subject => $subject) : ()),
493 (defined($template) ? (template => $template) : ()),
494 (defined($message_type) ? (message_type => $message_type) : ()),
495 body => $body,
496 };
497  
498 0 my $request = POST($self->api_base . '/messages',
499 'Content-Type' => 'application/json',
500 Content => JSON::XS::encode_json($json_content)
501 );
502  
503 0 return $self->_request($request);
504 }
505  
506  
507 0 ▶ method get_admins() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine get_admins: not called CC=3 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
508 0 my $request = GET($self->api_base . '/admins/',
509 'Content-Type' => 'application/json');
510
511 0 return $self->_request($request);
512 }
513  
514  
515
516 0 ▶ method _request(HTTP::Request $request, Bool :$no_content?) {
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine _request: not called CC=24 SCAR=59.3
Branch: 12 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC10($request) or _failed_check(154, "InstanceOf[\"HTTP::Request\"]", $request, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
if ($#_ == 1 and ref $_[1] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'no_content'} ? : 0 0 0
if (exists $_{"no_content"}) 0 0 0
Type::Tiny::XS::Bool($no_content) or _failed_check(3, "Bool", $no_content, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 1 and ref $_[1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 1 and ref $_[1] eq "HASH"
$#_ == 1 ref $_[1] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 1B= ref $_[1] eq "HASH"
ABresult
0X0
100
111
517 0 $request->header('Accept', 'application/json');
518 0 $request->header('Authorization' => "Basic " . MIME::Base64::encode_base64($self->app_id . ":" . $self->api_key, ''));
519  
520 0 my $response = $self->ua->request($request);
521  
522 0 ▶ if ($response->is_success()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
523 0 ▶ if (!$no_content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_content) 0 0 0
524 0 my $data;
525 0 eval {
526 0 $data = JSON::XS::decode_json($response->content());
527 };
528 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
529 0 WebService::Intercom::Exception->throw({ message => "Failed to decode JSON result for request: " . $@ . "\n" . $request->as_string() . "\nResult was: " . $response->as_string()});
530 }
531 0 ▶ if ($data->{type} =~ /^(user|tag|note|user_message|admin_message)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($data->{'type'} =~ /^(user|tag|note|user_message|admin_message)$/u) { } 0 0 0
elsif ($data->{'type'} eq 'admin.list') { } 0 0 0
elsif ($data->{'type'} eq 'error.list') { } 0 0 0
532 0 my $class_name = "WebService::Intercom::" . ucfirst($1);
533 0 $class_name =~ s/(?:user_message|admin_message)$/Message/ig;
534 0 my $r;
535 0 eval {
536 0 $r = $class_name->new({
537 %$data,
538 intercom => $self,
539 });
540 };
541 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
542 0 WebService::Intercom::Exception->throw({ message => "Failed to decode JSON result to object: " . $@ . "\n" . $request->as_string() . "\nResult was: " . $response->as_string()});
543 }
544 0 return $r;
545 } elsif ($data->{type} eq 'admin.list') {
546 0 my @admins = map { WebService::Intercom::Admin->new($_) } @{$data->{admins}};
547 0 return \@admins;
548 } elsif ($data->{type} eq 'error.list') {
549 WebService::Intercom::Exception->throw(
550 request_id => $data->{request_id},
551 message => $data->{errors}->[0]->{message},
552 code => $data->{errors}->[0]->{code}
553 0 );
554 } else {
555 0 WebService::Intercom::Exception->throw({ message => "Unknown object type returned: $data->{type}"});
556 }
557 }
558 0 return;
559 } else {
560 # Failed request but we still got some json content
561 0 ▶ if ($response->header('Content-Type') =~ /json/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->header("Content-Type") =~ /json/u) 0 0 0
562 0 my $data;
563 0 eval {
564 0 $data = JSON::XS::decode_json($response->content());
565 };
566 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
567 0 WebService::Intercom::Exception->throw({ message => "Failed to decode JSON result for request " . $request->as_string() . "\nResult was: " . $response->as_string()});
568 }
569 WebService::Intercom::Exception->throw(
570 request_id => $data->{request_id},
571 message => $data->{errors}->[0]->{message},
572 code => $data->{errors}->[0]->{code}
573 0 );
574 }
575 }
576 0 WebService::Intercom::Exception->throw({ message => "Got a bad response from request:\n" . $request->as_string() . "\nResult was: " . $response->as_string()});
577 }
578 }
579  
580
581 2 1;
582  
583 __END__
↑ Summary Intercom/User.pm »