File Coverage

blib/lib/STIX/Common/Properties.pm
Criterion Covered Total %
statement 35 36 97.2
branch 0 2 0.0
condition n/a
subroutine 12 13 92.3
pod n/a
total 47 51 92.1


line stmt bran cond sub pod time code
1             package STIX::Common::Properties;
2              
3 26     26   17076 use 5.010001;
  26         156  
4 26     26   274 use strict;
  26         57  
  26         772  
5 26     26   128 use warnings;
  26         45  
  26         1413  
6 26     26   141 use utf8;
  26         112  
  26         205  
7              
8 26     26   1234 use Carp;
  26         256  
  26         2370  
9 26     26   281 use STIX::Common::List;
  26         75  
  26         809  
10 26     26   12982 use STIX::Common::Timestamp;
  26         104  
  26         1524  
11 26     26   267 use Types::Standard qw(Str StrMatch Num ArrayRef HashRef Bool InstanceOf);
  26         48  
  26         391  
12 26     26   111023 use Types::TypeTiny qw(ArrayLike);
  26         59  
  26         210  
13              
14 26     26   16035 use Moo;
  26         64  
  26         170  
15 26     26   12864 use namespace::autoclean;
  26         59  
  26         276  
16              
17             extends 'STIX::Object';
18              
19 26         20081 use constant SCHEMA =>
20 26     26   2827 'http://raw.githubusercontent.com/oasis-open/cti-stix2-json-schemas/stix2.1/schemas/common/core.json';
  26         73  
21              
22             has type => (is => 'rw', default => sub { shift->STIX_OBJECT_TYPE }, required => 1);
23              
24             has spec_version => (is => 'rw', default => '2.1');
25              
26             has id => (
27             is => 'rw',
28             isa => StrMatch [
29             qr{^[a-z][a-z0-9-]+[a-z0-9]--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$}
30             ],
31             default => sub { shift->generate_id }
32             );
33              
34             has created_by_ref => (is => 'rw', isa => InstanceOf ['STIX::Common::Identifier', 'STIX::Object']);
35              
36             has created => (
37             is => 'rw',
38             coerce => sub { ref($_[0]) ? $_[0] : STIX::Common::Timestamp->new($_[0]) },
39             isa => InstanceOf ['STIX::Common::Timestamp'],
40             default => sub { STIX::Common::Timestamp->new }
41             );
42              
43             has modified => (
44             is => 'rw',
45             coerce => sub { ref($_[0]) ? $_[0] : STIX::Common::Timestamp->new($_[0]) },
46             isa => InstanceOf ['STIX::Common::Timestamp'],
47             default => sub { shift->created }
48             );
49              
50             has revoked => (is => 'rw', isa => Bool);
51              
52             has labels => (is => 'rw', isa => ArrayLike [Str], default => sub { STIX::Common::List->new });
53              
54             has confidence => (is => 'rw', isa => Num);
55              
56             has lang => (is => 'rw', isa => Str);
57              
58             has external_references => (
59             is => 'rw',
60             isa => ArrayLike [InstanceOf ['STIX::Common::ExternalReference']],
61             default => sub { STIX::Common::List->new }
62             );
63              
64             has object_marking_refs => (
65             is => 'rw',
66             isa => ArrayLike [InstanceOf ['STIX::Common::Identifier', 'STIX::Object']],
67             default => sub { STIX::Common::List->new }
68             );
69              
70             has granular_markings => (
71             is => 'rw',
72             isa => ArrayLike [InstanceOf ['STIX::Common::GranularMarking']],
73             default => sub { STIX::Common::List->new }
74             );
75              
76             has defanged => (is => 'rw', isa => Bool, trigger => 1);
77              
78             has extensions => (is => 'rw');
79              
80             has custom_properties => (is => 'rw', isa => HashRef, default => sub { {} });
81              
82              
83             sub _trigger_defanged {
84 0 0   0     Carp::croak '"defanged": This property MUST NOT be used on any STIX Objects other than SCOs.'
85             unless shift->STIX_OBJECT eq 'SCO';
86             }
87              
88             1;
89              
90             =encoding utf-8
91              
92             =head1 NAME
93              
94             STIX::Common::Properties - STIX Common Properties
95              
96             =head1 SYNOPSIS
97              
98             use STIX::Common::Properties;
99              
100             my $object = STIX::Common::Properties->new();
101              
102              
103             =head1 DESCRIPTION
104              
105             Common properties and behavior across all STIX Domain Objects and STIX
106             Relationship Objects.
107              
108              
109             =head2 METHODS
110              
111             L inherits all methods from L
112             and implements the following new ones.
113              
114             =over
115              
116             =item STIX::Common::Properties->new(%properties)
117              
118             Create a new instance of L.
119              
120             =item $object->confidence
121              
122             Identifies the confidence that the creator has in the correctness of their
123             data.
124              
125             =item $object->created
126              
127             The created property represents the time at which the first version of this
128             object was created. The timstamp value MUST be precise to the nearest
129             millisecond.
130              
131             =item $object->created_by_ref
132              
133             The ID of the Source object that describes who created this object.
134              
135             =item $object->custom_properties
136              
137             Additional custom properties (deprecated in STIX 2.1).
138              
139             $object->custom_properties(
140             x_acme_org_risk_score => 10,
141             x_acme_org_scoring => {
142             impact => 'high',
143             probability => 'low'
144             }
145             );
146              
147             =item $object->extensions
148              
149             Specifies any extensions of the object, as a dictionary.
150              
151             =item $object->external_references
152              
153             A list of external references which refers to non-STIX information.
154              
155             =item $object->granular_markings
156              
157             The set of granular markings that apply to this object.
158              
159             =item $object->id
160              
161             =item $object->labels
162              
163             The labels property specifies a set of terms used to describe this object.
164              
165             =item $object->lang
166              
167             Identifies the language of the text content in this object.
168              
169             =item $object->modified
170              
171             The modified property represents the time that this particular version of
172             the object was modified. The timstamp value MUST be precise to the nearest
173             millisecond.
174              
175             =item $object->object_marking_refs
176              
177             The list of marking-definition objects to be applied to this object.
178              
179             =item $object->revoked
180              
181             The revoked property indicates whether the object has been revoked.
182              
183             =item $object->spec_version
184              
185             The version of the STIX specification used to represent this object.
186              
187             =item $object->type
188              
189             The type property identifies the type of STIX Object (SDO, Relationship
190             Object, etc). The value of the type field MUST be one of the types defined
191             by a STIX Object (e.g., indicator).
192              
193             =back
194              
195              
196             =head2 HELPERS
197              
198             =over
199              
200             =item $object->TO_JSON
201              
202             Helper for JSON encoders.
203              
204             =item $object->to_hash
205              
206             Return the object HASH.
207              
208             =item $object->to_string
209              
210             Encode the object in JSON.
211              
212             =item $object->validate
213              
214             Validate the object using JSON Schema (see L).
215              
216             =back
217              
218              
219             =head1 SUPPORT
220              
221             =head2 Bugs / Feature Requests
222              
223             Please report any bugs or feature requests through the issue tracker
224             at L.
225             You will be notified automatically of any progress on your issue.
226              
227             =head2 Source Code
228              
229             This is open source software. The code repository is available for
230             public review and contribution under the terms of the license.
231              
232             L
233              
234             git clone https://github.com/giterlizzi/perl-STIX.git
235              
236              
237             =head1 AUTHOR
238              
239             =over 4
240              
241             =item * Giuseppe Di Terlizzi
242              
243             =back
244              
245              
246             =head1 LICENSE AND COPYRIGHT
247              
248             This software is copyright (c) 2024 by Giuseppe Di Terlizzi.
249              
250             This is free software; you can redistribute it and/or modify it under
251             the same terms as the Perl 5 programming language system itself.
252              
253             =cut