Apache-Solr

 view release on metacpan or  search on metacpan

lib/Apache/Solr/JSON.pm  view on Meta::CPAN


use Apache::Solr::Result ();
use HTTP::Request        ();
use JSON                 ();
use Scalar::Util         qw(blessed);


sub init($)
{   my ($self, $args) = @_;
    $args->{format}   ||= 'JSON';
    $self->SUPER::init($args);

    $self->{ASJ_json} = $args->{json} || JSON->new->utf8;
    $self;
}

#---------------

sub json() {shift->{ASJ_json}}

#--------------------------

lib/Apache/Solr/JSON.pm  view on Meta::CPAN

    if(ref $body && ref $body ne 'SCALAR')
    {   $body_ct ||= 'application/json; charset=utf-8';
        $body      = \$self->json->encode($body);
    }

    # Solr server 3.6.2 seems not to detect the JSON input from the
    # body content, so requires this work-around
    # https://solr.apache.org/guide/6_6/uploading-data-with-index-handlers.html#UploadingDatawithIndexHandlers-JSONUpdateConveniencePaths
    $url =~ s!/update\?!/update/json?!;

    my $resp = $self->SUPER::request($url, $result, $body, $body_ct);
    my $ct   = $resp->content_type;

    # At least until Solr 4.0 response ct=text/plain while producing JSON
    # $ct =~ m/json/i
    #     or error __x"Answer from solr server is not json but {type}"
    #          , type => $ct;

#warn $resp->decoded_content;
    my $dec = $self->json->decode($resp->decoded_content || $resp->content);

lib/Apache/Solr/XML.pm  view on Meta::CPAN

  , ContentKey   => '_'
  , KeyAttr      => []
  );
sub _cleanup_parsed($);


sub init($)
{   my ($self, $args) = @_;
    $args->{format} ||= 'XML';

    $self->SUPER::init($args);

    $self->{ASX_simple} = XML::LibXML::Simple->new(@xml_decode_config);
    $self;
}

#---------------
sub xmlsimple() {shift->{ASX_simple}}

#--------------------------

lib/Apache/Solr/XML.pm  view on Meta::CPAN

#--------------------------

sub request($$;$$)
{   my ($self, $url, $result, $body, $body_ct) = @_;

    if(blessed $body && $body->isa('XML::LibXML::Document'))
    {   $body_ct ||= 'text/xml; charset=utf-8';
        $body      = \$body->toString;
    }

    my $resp = $self->SUPER::request($url, $result, $body, $body_ct);
    my $ct   = $resp->content_type;
#warn $resp->as_string;
    $ct =~ m/xml/i or return $result;

    my $dec = $self->xmlsimple->XMLin(
        $resp->decoded_content || $resp->content,
        parseropts => {huge => 1},
    );

#warn Dumper $dec;



( run in 1.020 second using v1.01-cache-2.11-cpan-49f99fa48dc )