HTML::...Unique(3pm)

πŸ“¦
version 2.03 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– HTML::...Unique(3pm) πŸ’–

okay bestie, gather round, because this is the manpage for HTML::FormFu::Constraint::DBIC::Unique β€” the Perl module that keeps your database from having two of the same thing, no cap. It's a constraint for HTML::FormFu::Model::DBIC and honestly? iconic behaviour.

VERSION: version 2.03 ✨ (yes, we stan a numbered release)


🌈 SYNOPSIS 🌈

here's the vibe β€” you either wire it up in code:

$form->stash->{schema} = $dbic_schema; # DBIC schema

$form->element('text')
     ->name('email')
     ->constraint('DBIC::Unique')
     ->resultset('User')
     ;

$form->stash->{context} = $c; # Catalyst context

$form->element('text')
     ->name('email')
     ->constraint('DBIC::Unique')
     ->model('DBIC::User')
     ;

$form->element('text')
     ->name('user')
     ->constraint('DBIC::Unique')
     ->model('DBIC')
     ->resultset('User')
     ;

or in a config file:
---
elements:
  - type: text
    name: email
    constraints:
      - Required
      - type: DBIC::Unique
        model: DBIC::User
  - type: text
    name: user
    constraints:
      - Required
      - type: DBIC::Unique
        model: DBIC::User
        column: username

literally three ways to do the same thing and a config-file version too. pick your fighter πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

it checks if the input value exists in a DBIC ResultSet. that's it, that's the whole job. if it's already in there, the constraint is not having it. periodt.


πŸ‘‘ METHODS πŸ‘‘

πŸŽ€ model

Arguments: $string β€” a Catalyst model name like 'DBIC::User'

πŸŽ€ resultset

Arguments: $string β€” a DBIC resultset name like 'User'

πŸŽ€ self_stash_key

a reference to a key in the form stash. if this key exists, the constraint will check if the id matches the one of this element, so that you can use your own name. main character energy, honestly 🫢

πŸŽ€ id_field

use this key to define reference field which consist of primary key of resultset. if the field exists (and $self_stash_key not defined), the constraint will check if the id matches the primary key of row object:

---
elements:
  - type:  Hidden
    name:  id
    constraints:
      - Required

  - type:  Text
    name:  value
    label: Value
    constraints:
      - Required
      - type:       DBIC::Unique
        resultset:  ControlledVocab
        id_field:   id

πŸŽ€ others

use this key to manage unique compound database keys which consist of more than one column. for example, if a database key consists of 'category' and 'value', use a config file such as this:

---
elements:
  - type:  Text
    name:  category
    label: Category
    constraints:
      - Required

  - type:  Text
    name:  value
    label: Value
    constraints:
      - Required
      - type:       DBIC::Unique
        resultset:  ControlledVocab
        others:     category

two columns, one constraint, zero duplicates. slay 🧚

πŸŽ€ method_name

name of a method which will be called on the resultset. the method is passed two argument; the value of the field, and the primary key value (usually id) of the record in the form stash (as defined by self_stash_key). an example config might be:

---
elements:
  - type: text
    name: user
    constraints:
      - Required
      - type: DBIC::Unique
        model: DBIC::User
        method_name: is_username_available

πŸ”₯ SEE ALSO πŸ”₯

  • is a sub-class of, and inherits methods from HTML::FormFu::Constraint
  • HTML::FormFu::FormFu

πŸ’œ AUTHOR πŸ’œ

Jonas Alves <jgda@cpan.org>


🌸 LICENSE 🌸

this library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. πŸ’–


okay and the lil footer tea: this is perl v5.36.0, dated 2022-11-20, and the page you just read is HTML::...Unique(3pm). that's a wrap bestie, go make your database exclusive πŸŽ€βœ¨πŸ‘‘

πŸ“¦ where this page comes from