File Coverage

blib/lib/STIX/Relationship.pm
Criterion Covered Total %
statement 38 38 100.0
branch n/a
condition n/a
subroutine 13 13 100.0
pod n/a
total 51 51 100.0


line stmt bran cond sub pod time code
1             package STIX::Relationship;
2              
3 24     24   628 use 5.010001;
  24         112  
4 24     24   179 use strict;
  24         57  
  24         721  
5 24     24   123 use warnings;
  24         52  
  24         1545  
6 24     24   198 use utf8;
  24         73  
  24         230  
7              
8 24     24   1086 use STIX::Common::List;
  24         81  
  24         979  
9 24     24   137 use Types::Standard qw(Str InstanceOf);
  24         85  
  24         264  
10 24     24   85707 use Types::TypeTiny qw(ArrayLike);
  24         71  
  24         248  
11              
12 24     24   14765 use Moo;
  24         68  
  24         219  
13 24     24   11698 use namespace::autoclean;
  24         61  
  24         314  
14              
15             extends 'STIX::Common::Properties';
16              
17 24         2905 use constant SCHEMA =>
18 24     24   2802 'http://raw.githubusercontent.com/oasis-open/cti-stix2-json-schemas/stix2.1/schemas/sros/relationship.json';
  24         87  
19              
20 24         1957 use constant PROPERTIES => (
21             qw(type spec_version id created modified),
22             qw(created_by_ref revoked labels confidence lang external_references object_marking_refs granular_markings extensions),
23             qw(relationship_type description source_ref target_ref start_time stop_time)
24 24     24   187 );
  24         62  
25              
26 24     24   157 use constant STIX_OBJECT => 'SRO';
  24         51  
  24         1346  
27 24     24   142 use constant STIX_OBJECT_TYPE => 'relationship';
  24         55  
  24         9084  
28              
29             around BUILDARGS => sub {
30              
31             my ($orig, $class, @args) = @_;
32              
33             return {source_ref => $args[0], relationship_type => $args[1], target_ref => $args[2]}
34             if @args == 3 && !ref $args[1];
35              
36             return $class->$orig(@args);
37              
38             };
39              
40              
41             has relationship_type => (is => 'rw', required => 1);
42             has description => (is => 'rw', isa => Str);
43             has source_ref => (is => 'rw', required => 1, isa => InstanceOf ['STIX::Common::Identifier', 'STIX::Object']);
44             has target_ref => (is => 'rw', required => 1, isa => InstanceOf ['STIX::Common::Identifier', 'STIX::Object']);
45              
46             has start_time => (
47             is => 'rw',
48             isa => InstanceOf ['STIX::Common::Timestamp'],
49             coerce => sub { ref($_[0]) ? $_[0] : STIX::Common::Timestamp->new($_[0]) },
50             );
51              
52             has stop_time => (
53             is => 'rw',
54             isa => InstanceOf ['STIX::Common::Timestamp'],
55             coerce => sub { ref($_[0]) ? $_[0] : STIX::Common::Timestamp->new($_[0]) },
56             );
57              
58             1;
59              
60             =encoding utf-8
61              
62             =head1 NAME
63              
64             STIX::Relationship - STIX Relationship Object (SRO) - Relationship
65              
66             =head1 SYNOPSIS
67              
68             use STIX::Relationship;
69              
70             my $relationship = STIX::Relationship->new();
71              
72              
73             =head1 DESCRIPTION
74              
75             The Relationship object is used to link together two SDOs in order to
76             describe how they are related to each other.
77              
78              
79             =head2 METHODS
80              
81             L inherits all methods from L
82             and implements the following new ones.
83              
84             =over
85              
86             =item STIX::Relationship->new(%properties)
87              
88             Create a new instance of L.
89              
90             =item $relationship->description
91              
92             A description that helps provide context about the relationship.
93              
94             =item $relationship->id
95              
96             =item $relationship->relationship_type
97              
98             The name used to identify the type of relationship.
99              
100             =item $relationship->source_ref
101              
102             The ID of the source (from) object.
103              
104             =item $relationship->start_time
105              
106             This optional timestamp represents the earliest time at which the
107             Relationship between the objects exists. If this property is a future
108             timestamp, at the time the updated property is defined, then this
109             represents an estimate by the producer of the intelligence of the earliest
110             time at which relationship will be asserted to be true.
111              
112             =item $relationship->stop_time
113              
114             The latest time at which the Relationship between the objects exists. If
115             this property is a future timestamp, at the time the updated property is
116             defined, then this represents an estimate by the producer of the
117             intelligence of the latest time at which relationship will be asserted to
118             be true.
119              
120             =item $relationship->target_ref
121              
122             The ID of the target (to) object.
123              
124             =item $relationship->type
125              
126             The type of this object, which MUST be the literal C.
127              
128             =back
129              
130              
131             =head2 HELPERS
132              
133             =over
134              
135             =item $relationship->TO_JSON
136              
137             Encode the object in JSON.
138              
139             =item $relationship->to_hash
140              
141             Return the object HASH.
142              
143             =item $relationship->to_string
144              
145             Encode the object in JSON.
146              
147             =item $relationship->validate
148              
149             Validate the object using JSON Schema (see L).
150              
151             =back
152              
153              
154             =head1 SUPPORT
155              
156             =head2 Bugs / Feature Requests
157              
158             Please report any bugs or feature requests through the issue tracker
159             at L.
160             You will be notified automatically of any progress on your issue.
161              
162             =head2 Source Code
163              
164             This is open source software. The code repository is available for
165             public review and contribution under the terms of the license.
166              
167             L
168              
169             git clone https://github.com/giterlizzi/perl-STIX.git
170              
171              
172             =head1 AUTHOR
173              
174             =over 4
175              
176             =item * Giuseppe Di Terlizzi
177              
178             =back
179              
180              
181             =head1 LICENSE AND COPYRIGHT
182              
183             This software is copyright (c) 2024 by Giuseppe Di Terlizzi.
184              
185             This is free software; you can redistribute it and/or modify it under
186             the same terms as the Perl 5 programming language system itself.
187              
188             =cut