Random notes: | |
no link to Intro from the main POD | |
complicated synopsis is not a proper introduction | |
V::C second synopsis block is broken | |
shortened function names in synopsis are bad | |
don't tell me what V::C is not, tell me what it is | |
'fld' creates "attr(s) w/rules", 'has' is "just an attr", why two words? | |
... | |
At this point I still don't know how to do anything useful with one-liner, and have no idea which part of code does the actual validation. | |
I tried this: | |
perl -E 'package X; use Data::Dumper; use Validation::Class; field foo => { required => 1, min_length => 2 }; X->new(foo => 5)' | |
and it does nothing | |
I'm probably cargo-culting and don't get something trivial... | |
Oh well, I guess I should read the whole KEYWORDS section now or Intro. | |
... | |
Re-read SYNOPSIS once again. Trying to understand why it's so confusing. | |
Here's what I see in it: | |
- you create fields (I assume it's something like Mo* attributes) | |
- you pass the list of attribute name/values in constructor | |
But I tried to do the one-liner above and found that: | |
1) new() parameters are not stored anywhere | |
2) and they are not validated | |
3) maybe they're just for 'mth create', but then why are they constructor's parameters? | |
... | |
Nope, it's just the broken synopsis. | |
I tried to run it with name => 'f' and it does nothing, even though there's 'min_length => 2' in name's declaration. | |
(30 minutes since I started) | |
Finally reading Intro. | |
"Recently I've been experimenting with using Validation::Class to provide a..." is not a good start. | |
Does this sentence explain the main use-case of validation, or some exotic non-standard use-case? | |
... | |
"Die On Your Own Terms" could explain why I don't get any errors, but it still doesn't explain why X is empty. | |
It must be something else. | |
"A Reasonably Realistic Example" looks like it would work, but I'm too lazy to copy-paste it into 4 different files to check. | |
Looks like I must have several classes and use this $app->class(...) method to get it working. Or do I? | |
Too much magic :( | |
... | |
Oh. | |
Finally. | |
perl -E 'package X; use Data::Dumper; use Validation::Class; field foo => { required => 1, min_length => 2 }; method check => { input => [qw/ foo /], using => sub {} }; my $x = X->new(foo => "aa"); $x->ignore_failure(0); $x->report_failure(1); say $x->foo' | |
aa | |
Dumper($x) is empty because it's inside-out. | |
It doesn't validate 'foo' in constructor at all, but if I call '->check', it DTRT. | |
At this point (almost an hour after I started) I'm beginning to understand "how" but don't get the "why". It looks like Moose's attributes with type constraints, but with optional/configurable error handling (I see how this is useful) and without validating in the constructor (WTF?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment