<<

# Bugzilla::Field::Choice

- NAME
- SYNOPSIS
- DESCRIPTION
- METHODS
  - Class Factory
  - Mutators

# NAME

Bugzilla::Field::Choice - A legal value for a <select>-type field.

# SYNOPSIS

     my $field = new Bugzilla::Field({name => 'bug_status'});

     my $choice = new Bugzilla::Field::Choice->type($field)->new(1);

     my $choices = Bugzilla::Field::Choice->type($field)->new_from_list([1,2,3]);
     my $choices = Bugzilla::Field::Choice->type($field)->get_all();
     my $choices = Bugzilla::Field::Choice->type($field->match({ sortkey => 10 });

# DESCRIPTION

This is an implementation of Bugzilla::Object, but with a twist. You can't call any class methods (such as `new`, `create`, etc.) directly on `Bugzilla::Field::Choice` itself. Instead, you have to call `Bugzilla::Field::Choice->type($field)` to get the class you're going to instantiate, and then you call the methods on that.

We do that because each field has its own database table for its values, so each value type needs its own class.

See the "SYNOPSIS" for examples of how this works.

This class implements Bugzilla::Field::ChoiceInterface, and so all methods of that class are also available here.

# METHODS

## Class Factory

In object-oriented design, a "class factory" is a method that picks and returns the right class for you, based on an argument that you pass.

`type`

  Takes a single argument, which is either the name of a field from the `fielddefs` table, or a Bugzilla::Field object representing a field.

  Returns an appropriate subclass of `Bugzilla::Field::Choice` that you can now call class methods on (like `new`, `create`, `match`, etc.)

  NOTE: YOU CANNOT CALL CLASS METHODS ON `Bugzilla::Field::Choice`. You must call `type` to get a class you can call methods on.

## Mutators

This class implements mutators for all of the settable accessors in Bugzilla::Field::ChoiceInterface.

<<