HTTP/Accept.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 74 CC 6 SCAR 30.9
CC
6
Cov
0%
parse
42.0
empty
2.0
BEGIN
2.0
CRAP 22.0
1 # HTTP Accept line; Section 14.1 of RFC 2616
2 #
3 # subclass of HTTP:Part; see that for interface requirements
4 #
5  
6 package IDS::DataSource::HTTP::Accept;
7  
8 use strict;
9 use warnings;
10 use Carp qw(carp confess);
11 use base qw(IDS::DataSource::HTTP::Part);
12 use IDS::DataSource::HTTP::AcceptParams;
13  
14 $IDS::DataSource::HTTP::Accept::VERSION = "1.0";
15  
16 sub empty {
17 my $self = shift;
18 undef $self->{"data"}, $self->{"tokens"};
19 }
20  
21 sub parse {
22 my $self = shift;
23 my $accept = $self->{"data"}; # convenience
24 my $OK = 1; # optimism
25 my @tokens = ();
26  
27 $self->mesg(1, *parse{PACKAGE} . "::parse: data '$accept'");
28  
29 # the pattern below contains .+ which I do not think are in the
30 # standard, but they show up.
31 # my $accept_pattern = qr!^(\*|(\w+))/([-+.*\w]+)(;.*)?$!; # original
32 my $accept_pattern = qr!^(\*|(\w+))(/([-+.*\w]+))?(;\s*.*)?$!;
33 for my $token (split /,\s*/, $accept) { # standard says \s+, but \s*
34 # covers non-standard agents also.
35 $self->mesg(3, " token '$token'");
36 if ($token =~ m!$accept_pattern!) {
37 my $type = $1;
38 my $subtype = defined($4) ? $4 : "Nonstandard: nosubtype";
39 my $params = $5;
40 $self->mesg(3, " type '$type' subtype '$subtype'");
41 push @tokens, "Accept type: $type", "Accept subtype: $subtype";
42 if (defined($params)) {
43 $self->mesg(3, " params '$params'");
44 my $pobj = IDS::DataSource::HTTP::AcceptParams->new($self->{"params"}, $params);
45 push @tokens, $pobj->tokens();
46 }
47 } else {
48 my $pmsg = *parse{PACKAGE} . "::parse: In " .
49 ${$self->{"params"}}{"source"} .
50 " invalid accept in '$token'\n";
51 $self->warn($pmsg, \@tokens, "!Invalid accept value");
52 $OK = 0;
53 }
54 }
55  
56 $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ",
57 "\n ", \@tokens);
58 if (exists(${$self->{"params"}}{"Syntax only"}{"Accept"}) &&
59 ${$self->{"params"}}{"Syntax only"}{"Accept"}) {
60 $self->{"tokens"} = [ $OK ? "Accept syntax OK"
61 : "Accept syntax NOT OK" ];
62 } else {
63 $self->{"tokens"} = \@tokens;
64 }
65 }
66  
67 # accessor functions not provided by the superclass
68  
69 =head1 AUTHOR INFORMATION
70  
71 Copyright 2005-2007, Kenneth Ingham. All rights reserved.
72  
73 This library is free software; you can redistribute it and/or modify
74 it under the same terms as Perl itself.
75  
76 Address bug reports and comments to: ids_test at i-pi.com. When sending
77 bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm,
78 IDS::DataSource.pm, the version of Perl, and the name and version of the
79 operating system you are using. Since Kenneth is a PhD student, the
80 speed of the reponse depends on how the research is proceeding.
81  
82 =head1 BUGS
83  
84 Please report them.
85  
86 =head1 SEE ALSO
87  
88 L<IDS::Algorithm>, L<IDS::DataSource>
89  
90 =cut
91  
92  
93 1;