HTTP/Agent.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 63 CC 5 SCAR 27.7
CC
5
Cov
0%
parse
30.0
empty
2.0
BEGIN
2.0
CRAP 16.0
1 # HTTP Agent or User-Agent
2 # RFC 2616 section 14.43 (User-Agent)
3 # Agent is not in RFC 2616, but is common.
4 #
5 # subclass of HTTP:Part; see that for interface requirements
6 #
7  
8 package IDS::DataSource::HTTP::Agent;
9  
10 use strict;
11 use warnings;
12 use Carp qw(carp confess);
13 use base qw(IDS::DataSource::HTTP::Part);
14  
15 $IDS::DataSource::HTTP::Agent::VERSION = "1.0";
16  
17 sub empty {
18 my $self = shift;
19 undef $self->{"data"}, $self->{"tokens"};
20 }
21  
22 sub parse {
23 my $self = shift;
24 my $agent = $self->{"data"}; # convenience
25 my @tokens = ();
26 my $OK = 1; # optimism
27  
28 $self->mesg(1, *parse{PACKAGE} . "::parse: data '$agent'");
29  
30 unless ($agent =~ m!(\w+)/([\d.]+)( +\(([^\)]*)\))?!) {
31 push @tokens, "User agent: $agent";
32 $self->{"tokens"} = \@tokens;
33 return;
34 }
35 while (m!(\w+)/([\d.]+)( +\(([^\)]*)\))?!g) {
36 # below is correct; commented out because of code freeze for PhD
37 # while (m!(\w+)/([\d.]+)( +\((.*)\))?!g) {
38 push @tokens, "User agent: $1";
39 push @tokens, "User agent version: $2";
40 if (defined($3)) {
41 my $info = $4;
42 $self->mesg(2, *parse{PACKAGE} . "::parse: addl info '$info'");
43 push @tokens, map {"UA additional info: $_"} split /; +/, $info;
44 }
45 }
46  
47 $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ",
48 "\n ", \@tokens);
49 if (exists(${$self->{"params"}}{"Syntax only"}{"User-Agent"}) &&
50 ${$self->{"params"}}{"Syntax only"}{"User-Agent"}) {
51 $self->{"tokens"} = [ $OK ? "Agent syntax OK"
52 : "Agent syntax NOT OK" ];
53 } else {
54 $self->{"tokens"} = \@tokens;
55 }
56 }
57  
58 # accessor functions not provided by the superclass
59  
60 =head1 AUTHOR INFORMATION
61  
62 Copyright 2005-2007, Kenneth Ingham. All rights reserved.
63  
64 This library is free software; you can redistribute it and/or modify
65 it under the same terms as Perl itself.
66  
67 Address bug reports and comments to: ids_test at i-pi.com. When sending
68 bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm,
69 IDS::DataSource.pm, the version of Perl, and the name and version of the
70 operating system you are using. Since Kenneth is a PhD student, the
71 speed of the reponse depends on how the research is proceeding.
72  
73 =head1 BUGS
74  
75 Please report them.
76  
77 =head1 SEE ALSO
78  
79 L<IDS::Algorithm>, L<IDS::DataSource>
80  
81 =cut
82  
83  
84 1;