Badger...::Facet(3pm)

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

✨ NAME ✨

okay so bestie, this is Badger::Data::Facet πŸ’– β€” it's the base class validation facet for simple data types. yes, the base class. it's giving "blueprint that other facets copy homework from" energy πŸ‘‘


πŸ“œ SYNOPSIS πŸ“œ

TODO

like. literally TODO. the author said "not today" and honestly? relatable 🫢


πŸ™ˆ PLEASE NOTE πŸ™ˆ

bestie this is a work in progress, no cap. the implementation is subject to change and the documentation may be incomplete or incorrect in places. so like... don't @ me if something's off πŸ’€


🌸 DESCRIPTION 🌸

this module implements a base class validation facet for data types. that's it, that's the vibe. it's the parent class that does the validating-adjacent legwork so your subclasses can be the main character πŸ¦‹


πŸ’… METHODS πŸ’…

init($config)

the custom initialisation method for data facets ✨ subclasses may redefine this method to do something different β€” go off, customize. otherwise, the default behaviour goes like this:

first it looks for any $ARGS package variables (in the current class and any base classes) which denote the names of mandatory arguments for the data type.

our $ARGS = ['foo', 'bar'];

then it asserts that each of these is defined in the $config and copies the value into $self. mandatory means mandatory, bestie, no skipping πŸŽ€

any optional parameters can be specified using the $OPTS package variable.

our $OPTS = 'baz';              # single string is sugar for ['baz']

if any of these value(s) are defined in the $config then they will be copied into $self. cute, optional, lowkey effortless 🌈

validate($value,$type)

this is the main validation method for facets πŸ”₯ subclasses must redefine this method to implement their own validation routine. like, this is the whole point, bestie.

the first argument is a reference to the candidate value. for list and hash data types, this will be a reference to the list or hash respectively, as you would usually expect. but β€” and hear me out β€” if the value is a non-reference scalar (e.g. a number or text string) then a reference will also be passed. you may not be expecting this. ⚠️

$facet->validate(\$text);
$facet->validate(\@list);
$facet->validate(\%hash);

so yes, scalars get wrapped in a reference too. the way that everything gets a \ is so consistent of it πŸ’…

invalid($message)

this method is used internally (e.g. by the validate() method) to report invalid values.

$self->invalid("The value specified is not valid");

it's the "girl, no" button 😭

invalid_msg($format,@args)

this method is used internally (e.g. by the validate() method) to report invalid values using a pre-defined message() format.

our $MESSAGES = {
    not_orange => 'The colour specified is not orange: %s',
};

sub validate {
    my ($self, $value) = @_;

    return $$value eq 'orange'
        || $self->invalid_msg( not_orange => $$value );
}

same energy, but the message is pre-formatted. reusing your words? iconic πŸŽ€


🧚 PACKAGE VARIABLES 🧚

$MESSAGES

subclasses may defined their own message formats (for use with invalid_msg()) using the $MESSAGES package variable. this should be a reference to a hash array mapping short names to message formats. these formats are expanded using the xprintf()|Badger::Utils/xprintf() function in Badger::Utils. this is a wrapper around sprintf() with some extra syntactic sugar for handling positional arguments. ✨

our $MESSAGES = {
    # messages taking one and two parameters
    not_orange => 'The colour specified is not orange: %s',
    not_colour => 'The colour specified is not %s: %s',

    # message specifying parameters in a different order
    alt_colour => 'You specified the colour <2> but that is not <1>.',
};

not me loving that you can reorder the params with <1> and <2> β€” positional-argument girlies stay winning πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Andy Wardley <http://wardley.org/>


Copyright (C) 2001-2009 Andy Wardley. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


🫢 ACKNOWLEDGEMENTS 🫢

this module is derived from the XML::Schema::Facet module, also written by Andy Wardley under funding from Canon Research Europe Ltd. giving credit where credit is due, periodt πŸ’–


🌈 SEE ALSO 🌈

  • Badger::Data::Type::Simple

okay and that's the whole page, bestie!! this was Badger...::Facet(3pm) from the User Contributed Perl Documentation β€” page generated by perl v5.36.0 on 2023-08-28 πŸ¦‹πŸ’– mwah, go validate something cute ✨

πŸ“¦ where this page comes from