blib/lib/Zabbix7/API/Application.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 82 CC 2 SCAR 9.2
CC
2
Cov
0%
id
6.0
_readonly_properties
2.0
_prefix
2.0
CRAP 2.5
1 package Zabbix7::API::Application;
2
3 use strict;
4 use warnings;
5 use 5.010;
6 use Carp;
7 use autodie;
8 use utf8;
9 use Moo;
10 extends qw/Zabbix7::API::CRUDE/;
11 use Log::Any; # Added for debugging
12
13
14 has 'items' => (is => 'ro',
15 lazy => 1,
16 builder => '_fetch_items');
17 has 'host' => (is => 'ro',
18 lazy => 1,
19 builder => '_fetch_host');
20
21 sub id {
22 my ($self, $value) = @_;
23 if (defined $value) {
24 $self->data->{applicationid} = $value;
25 return $self->data->{applicationid};
26 }
27 return $self->data->{applicationid};
28 }
29
30 sub _readonly_properties {
31 return {
32 applicationid => 1,
33 hostid => 1, # hostid is read-only in Zabbix 7.0
34 flags => 1, # Added for Zabbix 7.0 (read-only)
35 };
36 }
37
38 sub _prefix {
39 my (undef, $suffix) = @_;
40 return 'application' . ($suffix // '');
41 }
42
43 sub _extension {
44 return (
45 output => 'extend',
46 selectItems => 'extend', # Added for Zabbix 7.0
47 selectHosts => ['hostid', 'host'], # Added for Zabbix 7.0
48 );
49 }
50
51 sub name {
52 my $self = shift;
53 return $self->data->{name} || '???';
54 }
55
56 sub _fetch_items {
57 my $self = shift;
58 my $items = $self->{root}->fetch('Item', params => { applicationids => [ $self->id ] });
59 Log::Any->get_logger->debug("Fetched " . scalar @$items . " items for application ID: " . $self->id);
60 return $items;
61 }
62
63 sub _fetch_host {
64 my $self = shift;
65 my $host = $self->{root}->fetch_single('Host', params => { applicationids => [ $self->id ] });
66 Log::Any->get_logger->debug("Fetched host for application ID: " . $self->id);
67 return $host;
68 }
69
70 before 'update' => sub {
71 my ($self) = @_;
72 delete $self->data->{hostid}; # hostid is read-only
73 delete $self->data->{flags}; # flags is read-only
74 };
75
76 1;
77 __END__