File Coverage

blib/lib/ThreatNet/Message.pm
Criterion Covered Total %
statement 18 18 100.0
branch 3 4 75.0
condition 3 3 100.0
subroutine 9 9 100.0
pod 4 4 100.0
total 37 38 97.3


line stmt bran cond sub pod time code
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
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     5   24788 use strict;
  5         12  
  5         437  
28             use overload 'bool' => sub () { 1 },
29 5         51 '""' => 'message',
30 5     5   6483 '+0' => 'event_time';
  5         4853  
31              
32 5     5   4047 use vars qw{$VERSION};
  5         13  
  5         392  
33             BEGIN {
34 5     5   1682 $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 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
57              
58             Returns a C object on success, false if the message is
59             not a valid message for a particular message class, or C on error,
60             such as being passed a non-string.
61              
62             =cut
63              
64             sub new {
65 28 50   28 1 3180 my $class = ref $_[0] ? ref shift : shift;
66 28 100       76 my $message = _STRING0($_[0]) ? shift : return undef;
67              
68             # Create the object
69 19         125 my $self = bless {
70             message => $message,
71             created => time(),
72             }, $class;
73              
74 19         243 $self;
75             }
76              
77             =pod
78              
79             =head2 message
80              
81             For any C class, the C 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     10 1 4789 sub message { $_[0]->{message} }
88              
89             =pod
90              
91             =head2 created
92              
93             The C method returns the unix epoch time that the
94             C 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 the time at which the event actually occured.
100              
101             Some protocols may supply the B event time independantly.
102              
103             Returns the unix epoch time in seconds as an integer.
104              
105             =cut
106              
107 22     22 1 1368 sub created { $_[0]->{created} }
108              
109             =pod
110              
111             =head2 event_time
112              
113             The C method returns the event time, or as close an estimate
114             as the object is capable of providing.
115              
116             Unless the C 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     8 1 27 sub event_time { $_[0]->created(@_) }
124              
125              
126              
127              
128              
129             #####################################################################
130             # Support Functions
131              
132             sub _STRING0 ($) {
133 28   100 28   205 !! (defined $_[0] and ! ref $_[0]);
134             }
135              
136             1;
137              
138             =pod
139              
140             =head1 SUPPORT
141              
142             All bugs should be filed via the bug tracker at
143              
144             L
145              
146             For other issues, or commercial enhancement and support, contact the author
147              
148             =head1 AUTHORS
149              
150             Adam Kennedy Eadamk@cpan.orgE
151              
152             =head1 SEE ALSO
153              
154             L, L
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