| 1 | package ThreatNet::Topic; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | ThreatNet::Topic - An object representation of a ThreatNet channel topic | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | ThreatNet is an evolving idea. This standalone module defines a topic format | ||||||||||||||||||||||||||||
| 12 | and an object to hold it. ThreatNet itself is not yet available. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | A proposal generally defining what it B<might> be is available at: | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | L<http://ali.as/devel/threatnetwork.html> | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use URI (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use overload 'bool' => sub () { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | '""' => 'topic'; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | $VERSION = '0.20'; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | ##################################################################### | ||||||||||||||||||||||||||||
| 37 | # Constructor and Accessors | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =pod | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 new $topic | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | The C<new> constructor takes a new ThreatNet topic string and creates an | ||||||||||||||||||||||||||||
| 44 | object that represents it. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | A ThreatNet topic should look like the following | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | threatnet://host/path configuration | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | That is, it should start with a 'threatnet' URI identifier in the same | ||||||||||||||||||||||||||||
| 51 | style as XML namespace URIs, containing at least the host and path | ||||||||||||||||||||||||||||
| 52 | components, following an arbitrary string most likely representing the | ||||||||||||||||||||||||||||
| 53 | configuration and rules of the channel, with a format defined by the | ||||||||||||||||||||||||||||
| 54 | protocol. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Returns a new ThreatNet::Topic object or C<undef> if the string is not a | ||||||||||||||||||||||||||||
| 57 | valid ThreatNet topic string. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 12 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 12 | ▶ | my $string = defined $_[0] ? shift : return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Create the object | ||||||||||||||||||||||||||||
| 66 | 12 | my $self = bless { | |||||||||||||||||||||||||||
| 67 | topic => $string, | ||||||||||||||||||||||||||||
| 68 | config => $string, | ||||||||||||||||||||||||||||
| 69 | }, $class; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Extract the header URI | ||||||||||||||||||||||||||||
| 72 | 12 | ▶ | $self->{config} =~ s/^(\S+)\s*// or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 9 | ▶ | $self->{URI} = URI->new("$1") or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Check the URI | ||||||||||||||||||||||||||||
| 76 | 9 | ▶ | $self->{URI}->scheme and $self->{URI}->scheme eq 'threatnet' or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"URI"}->scheme and $self->{"URI"}->scheme eq "threatnet"
MC/DC100%2/2
$self->{"URI"}->scheme and $self->{"URI"}->scheme eq "threatnet"
$self->{"URI"}->scheme
$self->{"URI"}->scheme eq "threatnet"
Truth table100%3/3
A and B
A= $self->{"URI"}->schemeB= $self->{"URI"}->scheme eq "threatnet"
| |||||||||||||||||||||||||||||
| 77 | 4 | ▶ | $self->{URI}->authority and $self->{URI}->authority or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"URI"}->authority and $self->{"URI"}->authority
MC/DC50%1/2
$self->{"URI"}->authority and $self->{"URI"}->authority
$self->{"URI"}->authority
$self->{"URI"}->authority
Truth table66%2/3
A and B
A= $self->{"URI"}->authorityB= $self->{"URI"}->authority
| |||||||||||||||||||||||||||||
| 78 | 3 | ▶ | $self->{URI}->path and $self->{URI}->path or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"URI"}->path and $self->{"URI"}->path
MC/DC50%1/2
$self->{"URI"}->path and $self->{"URI"}->path
$self->{"URI"}->path
$self->{"URI"}->path
Truth table66%2/3
A and B
A= $self->{"URI"}->pathB= $self->{"URI"}->path
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 2 | $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =pod | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head2 topic | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Accessor method that returns the Topic as a topic string. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 4 | ▶ | sub topic { $_[0]->{topic} } | ||||||||||||||||||||||||||
|
Subroutine
topic: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =pod | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head2 URI | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Accessor method that returns the protocol identifier as a URI object | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 4 | ▶ | sub URI { $_[0]->{URI} } | ||||||||||||||||||||||||||
|
Subroutine
URI: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =pod | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 config | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Accessor method that returns the non-required protocol-specific part of | ||||||||||||||||||||||||||||
| 108 | the topic, which is assumed to hold the channel configuration. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | ▶ | sub config { $_[0]->{config} } | ||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | 1; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =pod | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | All bugs should be filed via the bug tracker at | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ThreatNet-Topic> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | For other issues, or commercial enhancement and support, contact the author | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | L<http://ali.as/devel/threatnetwork.html> | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Copyright (c) 2004 Adam Kennedy. All rights reserved. | ||||||||||||||||||||||||||||
| 137 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 138 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 141 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||