HTTP/Encoding.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 49 CC 3 SCAR 17.5
CC
3
Cov
0%
parse
12.0
empty
2.0
BEGIN
2.0
CRAP 5.8
1 # HTTP Accept-Encoding line; section 14.3 of RFC 2616 applies here
2 # qvalues are from section 3.9
3 #
4 # subclass of HTTP:Part; see that for interface requirements
5 #
6  
7 package IDS::DataSource::HTTP::Encoding;
8  
9 use strict;
10 use warnings;
11 use Carp qw(carp confess);
12 use base qw(IDS::DataSource::HTTP::Part);
13  
14 $IDS::DataSource::HTTP::Encoding::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 ($type, $param, @tokens);
25  
26 $self->mesg(1, *parse{PACKAGE} . "::parse: data '$accept'");
27  
28 # Example line:
29 # Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0
30 my $pat = qr/[-a-zA-Z0-9!#\$%^&*_+|.~]+/; # missing '"` (3 chars)
31 # First, split at commas
32 for my $pref (split /,\s*/, $accept) {
33 $pref =~ /^([^;]+)(;.*)?/;
34 $type = $1;
35 $param = $2;
36 if ($type =~ /^$pat$/) {
37 push @tokens, "Encoding: $type";
38 } else {
39 my $pmsg = *parse{PACKAGE} . "::parse: In " .
40 ${$self->{"params"}}{"source"} .
41 " Invalid encoding: '$type'";
42 $self->warn($pmsg, \@tokens, "!Invalid encoding");
43 }
44  
45 # See if a parameter is present (e.g., qvalue)
46 if (defined($param)) {
47 my $pobj = new IDS::DataSource::HTTP::AcceptParams($self->{"params"}, $param);
48 push @tokens, $pobj->tokens();
49 }
50 }
51  
52 $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ",
53 "\n ", \@tokens);
54 $self->{"tokens"} = \@tokens;
55 }
56  
57 # accessor functions not provided by the superclass
58  
59 =head1 AUTHOR INFORMATION
60  
61 Copyright 2005-2007, Kenneth Ingham. All rights reserved.
62  
63 This library is free software; you can redistribute it and/or modify
64 it under the same terms as Perl itself.
65  
66 Address bug reports and comments to: ids_test at i-pi.com. When sending
67 bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm,
68 IDS::DataSource.pm, the version of Perl, and the name and version of the
69 operating system you are using. Since Kenneth is a PhD student, the
70 speed of the reponse depends on how the research is proceeding.
71  
72 =head1 BUGS
73  
74 Please report them.
75  
76 =head1 SEE ALSO
77  
78 L<IDS::Algorithm>, L<IDS::DataSource>
79  
80 =cut
81  
82 1;