File Coverage

lib/Neo4j/Driver/Result/Text.pm
Criterion Covered Total %
statement 27 27 100.0
branch 12 12 100.0
condition 6 8 75.0
subroutine 7 7 100.0
pod 0 1 100.0
total 52 55 96.3


line stmt bran cond sub pod time code
1 20     20   293 use v5.12;
  20         76  
2 20     20   116 use warnings;
  20         37  
  20         1659  
3              
4             package Neo4j::Driver::Result::Text 1.02;
5             # ABSTRACT: Fallback handler for result errors
6              
7              
8             # This package is not part of the public Neo4j::Driver API.
9              
10              
11 20     20   129 use parent 'Neo4j::Driver::Result';
  20         79  
  20         127  
12              
13             our @CARP_NOT = qw(Neo4j::Driver::Net::HTTP);
14              
15 20     20   2189 use Neo4j::Error;
  20         50  
  20         11891  
16              
17              
18             #our $ACCEPT_HEADER = "text/*; q=0.1";
19              
20              
21             sub new {
22             # uncoverable pod (private method)
23 11     11 0 35 my ($class, $params) = @_;
24            
25 11         25 my $header = $params->{http_header};
26 11         25 my $error = 'Neo4j::Error';
27            
28 11 100 100     89 if (! $header->{success} && ! $header->{status}) {
    100          
29             # Response generated internally by the networking module
30 1         4 $error = $error->append_new( Network => sprintf("HTTP error: %s", $params->{http_agent}->http_reason) );
31             }
32             elsif (! $header->{success}) {
33             $error = $error->append_new( Network => {
34             code => $header->{status},
35 4         26 as_string => sprintf("HTTP error: %s %s on %s to %s", $header->{status}, $params->{http_agent}->http_reason, $params->{http_method}, $params->{http_path}),
36             });
37             }
38            
39 11         51870 my ($content_type) = $header->{content_type} =~ m/^\s*([^\s;]*)/;
40 11 100 66     84 if (lc $content_type eq 'text/plain') {
    100          
    100          
41             $error = $error->append_new( Internal => {
42             as_string => $params->{http_agent}->fetch_all,
43 6         50 });
44             }
45             elsif ($content_type =~ m{^text/html\b|^application/xhtml\b}i) {
46 3         9 my $raw = $params->{http_agent}->fetch_all;
47 3         69 my ($title) = $raw =~ m{([^<]*)}i;
48 3 100       34 $error = $error->append_new( Internal => {
49             as_string => sprintf("Received HTML content%s from server (Is this a Neo4j server?)", $title ? " \"$title\"" : ""),
50             raw => $raw,
51             });
52             }
53             elsif ($content_type || $header->{status}) {
54             $error = $error->append_new( Internal => {
55             as_string => sprintf("Received %s content from database server; skipping result parsing", $content_type || "empty"),
56             raw => $params->{http_agent}->fetch_all,
57 1   50     9 });
58             }
59            
60 11         36529 return bless { _error => $error }, $class;
61             }
62              
63              
64 11     11   31 sub _info { shift }
65              
66              
67 1     1   10 sub _results { () } # no actual results provided here
68              
69              
70             # sub _accept_header { () }
71             #
72             #
73             # sub _acceptable {
74             # my ($class, $content_type) = @_;
75             #
76             # return $_[1] =~ m|^text/|i;
77             # }
78              
79              
80             1;