Form::Factory::Control::Choice - Helper class for tracking choices


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

Form::Factory::Control::Choice - Helper class for tracking choices

VERSION

Top

version 0.020

SYNOPSIS

Top

  my $foo = Form::Factory::Control::Choice->new('foo');
  my $bar = Form::Factory::Control::Choice->new('bar' => 'Bar');
  my $baz = Form::Factory::Control::Choice->new(
      label => 'Baz',
      value => 'baz',
  );
  my $qux = Form::Factory::Control::Choice->new({
      label => 'Qux',
      value => 'qux',
  });

DESCRIPTION

Top

These objects represent a single choice for a list or popup box. Each choice has a label and a value. The constructor is flexible to allow the following uses:

  my $choice = Form::Factory::Control::Choice->new($value) # $label = $value
  my $choice = Form::Factory::Control::Choice->new($value => $label);
  my $choice = Form::Factory::Control::Choice->new(
      label => $label,
      value => $value,
  );
  my $choice = Form::Factory::Control::Choice->new({
      label => $label,
      value => $value,
  });

If $value and $label are the same, all of those calls are identical.

ATTRIBUTES

Top

label

The label to give the choice.

value

The value of the choice.

AUTHOR

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Control::Choice;
BEGIN {
  $Form::Factory::Control::Choice::VERSION = '0.020';
}
use Moose;

has label => (
    is        => 'ro',
    isa       => 'Str',
);

has value => (
    is        => 'ro',
    isa       => 'Str',
    required  => 1,
);

sub BUILDARGS {
    my $class = shift;
    my %args;

    if (@_ == 1 and ref $_[0]) {
        %args = %{ $_[0] };
    }
    elsif (@_ == 1) {
        $args{value} = $_[0];
    }
    elsif (@_ == 2) {
        $args{value} = $_[0];
        $args{label} = $_[1];
    }
    else {
        %args = @_;
    }

    $args{label} = $args{value} unless defined $args{label};

    return $class->SUPER::BUILDARGS(%args);
}

1;