WebService::Solr::Field - A field object


WebService-Solr documentation Contained in the WebService-Solr distribution.

Index


Code Index:

NAME

Top

WebService::Solr::Field - A field object

SYNOPSIS

Top

    my $field = WebService::Solr::Field->new( foo => 'bar' );

DESCRIPTION

Top

This class represents a field from a document, which is basically a name-value pair.

ACCESSORS

Top

* name - the field's name
* value - the field's value
* boost - a floating-point boost value

METHODS

Top

new( $name => $value, \%options )

Creates a new field object. Currently, the only option available is a "boost" value.

BUILDARGS( @args )

A Moose override to allow our custom constructor.

to_element( )

Serializes the object to an XML::Easy::Element object.

to_xml( )

Serializes the object to xml.

AUTHORS

Top

Brian Cassidy <bricas@cpan.org>

Kirk Beers

COPYRIGHT AND LICENSE

Top


WebService-Solr documentation Contained in the WebService-Solr distribution.

package WebService::Solr::Field;

use XML::Easy::Element;
use XML::Easy::Content;
use XML::Easy::Text ();

sub new {
    my ( $class, $name, $value, $opts ) = @_;
    $opts ||= {};

    die "name required"  unless defined $name;
    die "value required" unless defined $value;

    my $self = {
        name  => $name,
        value => $value,
        %{ $opts },
    };

    return bless $self, $class;
}

sub name {
    my $self = shift;
    $self->{ name } = $_[ 0 ] if @_;
    return $self->{ name };
}

sub value {
    my $self = shift;
    $self->{ value } = $_[ 0 ] if @_;
    return $self->{ value };
}

sub boost {
    my $self = shift;
    $self->{ boost } = $_[ 0 ] if @_;
    return $self->{ boost };
}

sub to_element {
    my $self = shift;
    my %attr = ( $self->boost ? ( boost => $self->boost ) : () );

    return XML::Easy::Element->new(
        'field',
        { name => $self->name, %attr },
        XML::Easy::Content->new( [ $self->value ] ),
    );
}

sub to_xml {
    my $self = shift;

    return XML::Easy::Text::xml10_write_element( $self->to_element );
}

1;

__END__