HTTP/Charset.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 8 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 / 67 CC 5 SCAR 26.9
CC
5
Cov
0%
parse
30.0
empty
2.0
BEGIN
2.0
CRAP 14.7
1 # HTTP Accept-Charset line; section 14.2 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::Charset;
8  
9 use strict;
10 use warnings;
11 use Carp qw(carp confess);
12 use base qw(IDS::DataSource::HTTP::Part);
13 use IDS::DataSource::HTTP::AcceptParams;
14  
15 $IDS::DataSource::HTTP::Charset::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 $accept = $self->{"data"}; # convenience
25 my ($type, $param);
26 my @tokens = ();
27 my $OK = 1; # optimism
28  
29 $self->mesg(1, *parse{PACKAGE} . "::parse: data '$accept'");
30  
31 # Example line:
32 # Accept-Charset: iso-8859-5, unicode-1-1;q=0.8
33 my $pat = qr/[-a-zA-Z0-9!#\$%^&*_+|.~]+/; # missing '"` (3 chars)
34 # First, split at commas
35 for my $pref (split /,\s*/, $accept) {
36 $pref =~ /^([^;]+)(;.*)?/;
37 $type = $1;
38 $param = $2;
39 if ($type =~ /^$pat$/) {
40 push @tokens, "Charset: $type";
41 } else {
42 push @tokens, "Invalid charset: $type";
43 $OK = 0;
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 if (exists(${$self->{"params"}}{"Syntax only"}{"Charset"}) &&
55 ${$self->{"params"}}{"Syntax only"}{"Charset"}) {
56 $self->{"tokens"} = [ $OK ? "Charset syntax OK"
57 : "Charset syntax NOT OK" ];
58 } else {
59 $self->{"tokens"} = \@tokens;
60 }
61 }
62  
63 # accessor functions not provided by the superclass
64  
65 =head1 AUTHOR INFORMATION
66  
67 Copyright 2005-2007, Kenneth Ingham. All rights reserved.
68  
69 This library is free software; you can redistribute it and/or modify
70 it under the same terms as Perl itself.
71  
72 Address bug reports and comments to: ids_test at i-pi.com. When sending
73 bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm,
74 IDS::DataSource.pm, the version of Perl, and the name and version of the
75 operating system you are using. Since Kenneth is a PhD student, the
76 speed of the reponse depends on how the research is proceeding.
77  
78 =head1 BUGS
79  
80 Please report them.
81  
82 =head1 SEE ALSO
83  
84 L<IDS::Algorithm>, L<IDS::DataSource>
85  
86 =cut
87  
88 1;