1 package SL::DB::Helper::VATIDNrValidation;
6 use SL::Locale::String qw(t8);
12 my ($self, $attribute) = @_;
14 my $number = SL::VATIDNr->clean($self->$attribute);
16 return () unless length($number);
17 return () if SL::VATIDNr->validate($number);
18 return ($::locale->text("The VAT ID number '#1' is invalid.", $self->$attribute));
22 my ($package, @attributes) = @_;
24 my $caller_package = caller;
25 @attributes = qw(ustid) unless @attributes;
29 *{ $caller_package . '::validate_vat_id_numbers' } = sub {
32 return map { SL::DB::Helper::VATIDNrValidation::_validate($self, $_) } @attributes;
46 SL::DB::Helper::VATIDNrValidation - Mixin for validating VAT ID number attributes
50 package SL::DB::SomeObject;
51 use SL::DB::Helper::VATIDNrValidation [ ATTRIBUTES ];
58 push @errors, $self->validate_vat_id_numbers;
63 This mixin provides a function C<validate_vat_id_numbers> that returns
64 a list of error messages, one for each attribute that fails the VAT ID
65 number validation. If all attributes are valid or empty then an empty
68 The names of attributes to check can be given as an import list to the
69 mixin package. If no attributes are given the single attribute C<ustid>
76 =item C<validate_vat_id_numbers>
78 This function iterates over all configured attributes and validates
79 their content according to how VAT ID numbers are supposed to be
80 formatted in the European Union (or the enterprise identification
81 numbers in Switzerland). An attribute that is undefined, empty or
82 consists solely of whitespace is considered valid, too.
84 The function returns a list of human-readable error messages suitable
85 for use in a general C<validate> function (see SYNOPSIS). For each
86 attribute failing the check the list will include one error message.
88 If all attributes are valid then an empty list is returned.
98 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>