ThreatNet/Message.pm

filter: Statementstmt 100% 19 / 19 Branchbran 75.0% 3 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 97.5% 40 / 41 CC 4 SCAR 5.1
CC
4
Cov
96%
new
3.0
_STRING0
2.0
BEGIN
1.0
CRAP 1.7
« ThreatNet.pm ↑ Summary ThreatNet/Filter.pm »
1 package ThreatNet::Message;
2  
3 =pod
4  
5 =head1 NAME
6  
7 ThreatNet::Message - An object representation of a ThreatNet channel message
8  
9 =head1 DESCRIPTION
10  
11 ThreatNet is an evolving idea. It's homepage at time of publishing is
12  
13 L<http://ali.as/threatnet/>
14  
15 This module is an abstract base class for a ThreatNet channel message,
16 and allows you to create objects representing threat messages in a channel.
17  
18 ThreatNet itself is not yet available and this module has been uploaded
19 seperately so people working on ThreatNet can play with the various
20 compenents in different ways before we come to a decision about what
21 collection of modules will be included in a core ThreatNet.pm package.
22  
23 =head1 METHODS
24  
25 =cut
26  
27 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use overload 'bool' => sub () { 1 },
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 '""' => 'message',
30 5 '+0' => 'event_time';
31  
32 5 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 $VERSION = '0.20';
35 }
36  
37  
38  
39  
40  
41 #####################################################################
42 # Base Constructor
43  
44 =pod
45  
46 =head2 new $message
47  
48 The C<new> constructor takes a string containing the actual channel message
49 and creates a new object. Please be aware that this method is likely to be
50 heavily overloaded, so there may be additional requirements.
51  
52 This base class is extremely flexible and makes absolutely no requirements
53 on the content of the message, even that is has length.
54  
55 For an example of a potentially more useful Message class, see
56 L<ThreatNet::Message::GenericIPv4>
57  
58 Returns a C<ThreatNet::Message> object on success, false if the message is
59 not a valid message for a particular message class, or C<undef> on error,
60 such as being passed a non-string.
61  
62 =cut
63  
64 28 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
65 28 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 28 28
66 28 ▶ my $message = _STRING0($_[0]) ? shift : return undef;
Branch: 1 branch
BranchTrueFalseTotal
&_STRING0($_[0]) ? : 19 9 28
67  
68 # Create the object
69 19 my $self = bless {
70 message => $message,
71 created => time(),
72 }, $class;
73  
74 19 $self;
75 }
76  
77 =pod
78  
79 =head2 message
80  
81 For any C<ThreatNet::Messsage> class, the C<message> accessor will always
82 return the message in string form, although it may have been canonicalised
83 and might not be identical to the original string.
84  
85 =cut
86  
87 10 ▶sub message { $_[0]->{message} }
Subroutine message: called CC=1 SCAR=0.0
Pod documented
88  
89 =pod
90  
91 =head2 created
92  
93 The C<created> method returns the unix epoch time that the
94 C<ThreatNet::Message> object was created (on the machine on which
95 the object was created).
96  
97 For some situations, this will be sufficient for use as the time
98 at which the event occured. Please be aware however, that it is
99 C<not> the time at which the event actually occured.
100  
101 Some protocols may supply the B<actual> event time independantly.
102  
103 Returns the unix epoch time in seconds as an integer.
104  
105 =cut
106  
107 22 ▶sub created { $_[0]->{created} }
Subroutine created: called CC=1 SCAR=0.0
Pod documented
108  
109 =pod
110  
111 =head2 event_time
112  
113 The C<event_time> method returns the event time, or as close an estimate
114 as the object is capable of providing.
115  
116 Unless the C<ThreatNet::Message> class is actually aware of the true
117 event time, it will generally estimate using the object creation time.
118  
119 Returns the unix epoch time in seconds as an integer.
120  
121 =cut
122  
123 8 ▶sub event_time { $_[0]->created(@_) }
Subroutine event_time: called CC=1 SCAR=0.0
Pod documented
124  
125  
126  
127  
128  
129 #####################################################################
130 # Support Functions
131  
132 28 ▶sub _STRING0 ($) {
Subroutine _STRING0: called CC=2 SCAR=6.9
133 28 ▶ !! (defined $_[0] and ! ref $_[0]);
Condition100%3/3
defined $_[0] && !ref($_[0])
!ll&&!rl&&r
2719
MC/DC100%2/2
defined $_[0] && !ref($_[0])
defined $_[0] !ref($_[0])
Truth table100%3/3
A && not(B)
A= defined $_[0]B= !ref($_[0])
ABresult
0X0
100
111
134 }
135  
136 5 1;
137  
138 =pod
139  
140 =head1 SUPPORT
141  
142 All bugs should be filed via the bug tracker at
143  
144 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ThreatNet-Message>
145  
146 For other issues, or commercial enhancement and support, contact the author
147  
148 =head1 AUTHORS
149  
150 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
151  
152 =head1 SEE ALSO
153  
154 L<http://ali.as/devel/threatnetwork.html>, L<ThreatNet::Topic>
155  
156 =head1 COPYRIGHT
157  
158 Copyright (c) 2004 - 2005 Adam Kennedy. All rights reserved.
159 This program is free software; you can redistribute
160 it and/or modify it under the same terms as Perl itself.
161  
162 The full text of the license can be found in the
163 LICENSE file included with this module.
164  
165 =cut
« ThreatNet.pm ↑ Summary ThreatNet/Filter.pm »