The web in a box - a next generation web framework for the Perl programming language

IRC log for #mojo, 2015-06-26

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
00:11 neilhwatson joined #mojo
01:13 klapperl joined #mojo
01:48 zivester joined #mojo
02:10 noganex_ joined #mojo
02:13 bpmedley https://bitbucket.org/snippets/bpmedley/KzMy7#cl-14 <-- Would something like this be useful for validations?  Provide a namespace for different type of validations...
02:31 woz joined #mojo
02:53 sri bpmedley: what do you need it for?
03:04 hshong joined #mojo
03:19 sri does anyone else think $validation->file should be $validation->upload?
03:21 mattastrophe joined #mojo
03:24 mst sri: yes
03:24 mst sri: nicer name, I think, anyway
03:25 bpmedley sri: I'm wondering if a validation namespace would make it possible to more easily support different types of validations.  For example, file uploads and application specific validations.
03:32 woz joined #mojo
03:34 sri bpmedley: so you don't actually have a use case?
03:35 bpmedley sri: I'm a bit late; however, I was commenting on file validations.  Issue #812.
03:35 sri mst: only problem is that there is another prominent upload methon in another class with very different semantics :S
03:36 sri my $foo = $c->req->upload('foo')
03:37 sri very different
03:37 sri $validation->required('foo')->upload->size(1, 1024)
03:38 bpmedley Also, someone asked how to do database checks with the validation api.  If there were namespaces for different types of validators, then I'm thinking it would be possible to support file upload semantics and application logic validations easier.
03:41 mst sri: oh. errrr.
03:41 mst sri: ->payload or ->content or something maybe? (I don't like those that much either)
03:42 sri actually, all of those are already in use :S
03:42 sri even ->file is used
03:43 sri app->static->file('foo/bar.txt')
03:46 good_news_everyon joined #mojo
03:46 good_news_everyon [mojo] kraih pushed 1 new commit to master: http://git.io/vtZmz
03:46 good_news_everyon mojo/master 488e3c2 Sebastian Riedel: rename file to upload
03:46 good_news_everyon left #mojo
03:46 sri guess it really doesn't matter, might as well pick the one everybody likes best
03:47 mst sri: ->clown # like 'mime', but scarier
03:48 mst VALIDATION REQUIRED CLOWN
03:48 mst (sorry)
03:52 bpmedley https://bitbucket.org/snippets/bpmedley/okqxe <-- Something like this is what I was getting at.  Would it make sense to have the ability to add an application specific validator?
04:03 bpmedley I'm starting to think my question is not valid because helpers or custom code can be used for app specific validation.
04:06 disputin joined #mojo
04:17 tempire I'm heavily indifferent towards file validation
04:18 tempire If one can be heavily indifferent
04:29 stealthybox joined #mojo
04:33 stealthybox hi friends, I've got a quick question about best practice
04:33 stealthybox I've read about extending in templates and overriding sections,
04:33 stealthybox We are using that in our project.
04:33 Lee_ joined #mojo
04:34 stealthybox I'm curious about including other templates though.
04:34 stealthybox Do we render_to_string inside the template if we want to do that?
04:34 stealthybox I can't really find anything in the documentation that talks about what I'm looking for.
04:36 stealthybox To be clear, I want to "include" one template inside of many others at specific places.
04:37 bpmedley stealthybox: http://mojolicio.us/perldoc/Mojolicious/Plugin/DefaultHelpers#include <-- Perhaps?
04:37 stealthybox I think that's exactly what I was looking for
04:37 stealthybox will try it
05:02 lb sri: i went to bed ;)
05:05 ToApolytoXaos joined #mojo
05:52 jwang joined #mojo
06:22 woz joined #mojo
06:27 batman sri: yeah... so i was out drinking beer yesterday
06:28 marcusr batman: unacceptable!
06:28 batman (read the backlog now)
06:28 batman i like validation when it only does play key/value input/output validation. but i guess that ship has sailed now.
06:28 marcusr ;)
06:28 batman marcusr: yeah, i know. you should have been there too :)
06:32 dod joined #mojo
06:32 batman sri, jberger, Grinnz_: i don't think there's much to gain for this patch, but i'm not -1. i'm just not actively giving the thumbs up either.
06:33 * batman comments on github.
06:34 dod joined #mojo
06:40 marcusr batman: Yeah, except my family is coming today, so my wife would have been very unhappy with me if I didn't stay at home and tidyed.
06:40 marcusr batman: I'm super happy with my new house beer btw, you need to come visit soon :)
06:41 batman yeah. unhappy wife = awful :)
06:41 batman cool. let me know, and i'll be there
06:41 batman what kind of beer is that?
06:41 marcusr patersbier / belgian single
06:44 batman cool.
06:48 kaare joined #mojo
06:48 trone joined #mojo
06:51 marcusr it's my tweakd version of this http://www.northernbrewer.com/documentation/allgrain/AG-Patersbier.pdf
06:58 batman looks good :)
07:11 eseyman joined #mojo
07:14 berov joined #mojo
07:35 Vandal joined #mojo
08:28 lb sri: have you changed your opinion on http://pastie.org/9420422 ? We would still really love that feature
08:30 lb (or maybe just allow validation functions to mutate input...)
08:39 batman lb: why do you modify $self->input->{$name} ?
08:40 batman other than that i'm +1. i haven't thought much about the consequences, but i know my coworkers would love that feature.
08:43 lb (not sure what you're asking)
08:44 lb it's so much cleaner to validate something that has been cleaned up, and when we know a particular piece should be sanitized before we put it in database, clean it up before we send it back to the user
08:45 lb imagine a form with two inputs, the first is correct, but should really be uppercase, and the second field is missing, but is required - why not redraw the form with the first field uppercased
09:22 AndrewIsh joined #mojo
09:22 batman lb: you do $self->input->{$name} = $output->{$name} = your_filter_code()
09:22 batman oh. i think i get it now. maybe i should rather ask why you modify output :)
09:23 batman lb: also, could you type "batman" first when you respond? i don't follow the channel, but i get notification when mentioned.
09:27 lb sorry, old habit :)
09:27 lb batman: see did it again
09:28 batman right.
09:28 batman it's not so much for my sake, just know i will probably respond **where async** if you don't prefix with my nick.
09:28 batman where? *very*
09:29 lb batman: batman
09:29 batman a conversation goes smoother when the other person responds :)
09:29 lb i think that's a requirement ;)
09:36 batman so.. why do you set $output->{$name} when running the filter function?
09:37 batman lb: i would suppose you want to do something like this $v->required("foo")->filter("trim")->like(qr{^\w+}); ?
09:38 bin_005 joined #mojo
10:13 lb yes
10:14 lb $v->required("phone")->filter("removeallwhitespace")->is_phonenum->filter("pretty_phonenumber");
10:14 lb or something
10:15 batman then i'm -1
10:15 lb batman: if checks were able to mutate, it could be (by convention)
10:15 lb $v->required("phone")->removeallwhitespace->is_phonenum->prettyphonenumber ;)
10:15 batman at least i think so: i don't think it should end up in $output, unless validated
10:15 lb oh i agree
10:16 lb validate, or leave unchanged, but if it validated, might as well turn it into something pretty
10:16 bin_005 joined #mojo
10:16 lb which is the problem with modifying input directly, of course
10:17 batman yeah... maybe... i need to think about it. i'm not instantly agreeing on that, which kind of makes the api a bit...strange
10:17 batman i think about your filter idea, like coercion. (https://metacpan.org/pod/Type::Coercion)
10:18 lb (the code i linked to was sri's btw :) )
10:18 batman which means it happens before you use the value.
10:18 batman ok
10:18 lb i'm not too hung up on the specifics, i'd just like to be able to mutate params during validation because of whitespace, case etc
10:19 batman but i guess, since there's no forced coercion, then being able to run the filter before and after kind of makes sense i guess...
10:19 batman maybe leave out the $output->{$name} unless exists $output->{$name}
10:20 batman lb: i see. well, i'm +1 to the idea
10:20 wingfold joined #mojo
10:20 lb we have some nice declarative validation going, but data-cleaning is a bit of a mess
10:21 batman :)
10:34 bpmedley lb: Could you use a plugin to do the filters?
10:35 batman bpmedley: not without monkey patching. these are not helpers.
10:36 ToApolytoXaos joined #mojo
10:41 ashimema joined #mojo
10:46 pink_mist Grinnz_: I just found out about this little module that seems somewhat useful for your SetUserGroup plugin: http://perldoc.perl.org/User/grent.html ... there's also http://perldoc.perl.org/User/pwent.html
10:46 pink_mist could make parts of the code more readable?
11:04 neilhwatson joined #mojo
11:11 bpmedley https://bitbucket.org/snippets/bpmedley/okqnx <-- How is this for a filter?
11:26 batman bpmedley: that's cool :)
11:27 batman i think it's slower than putting it into validation, but it's still very cool imo
11:29 bpmedley batman: Thx; it could be slower, I dunno.  However, is validation the correct place for a filter?  (brb)
11:30 batman bpmedley: good question. i don't even have a subjective *correct* answer :)
11:30 batman i think "yes", but i'm not sure.
11:30 dvinciguerra joined #mojo
11:31 lb bpmedley: in my opinion, you need to filter stuff before validating it and then maybe clean up the validated value, so it sorta has to
11:31 lb since you can chain validations in mojo, it makes sense to be able to chain filters as well
11:31 batman lb: i'm not sure about the last step. that's what makes it complicated to put into validation.
11:31 batman "clean up validated value" == why isn't it already clean enough?
11:32 lb like spaces in phone numbers
11:34 batman that doesn't answer my question. i get that you might want to do $v->required("foo")->to_lowercase->trim->like(qr{foo}); but i don't get why you want to filter _after_ ->like()
11:34 lb if you support filter->check->check, check->filter->check, filter->check->filter->check, why not filter->check->filter
11:35 batman i will try once again....
11:35 batman in which case do you want that?
11:35 batman i'm not asking if you should be able to. i'm asking if you can tell me when you want that.
11:35 batman give me an example
11:35 lb $v->required("phone")->removeallwhitespace->is_phonenum->prettyphonenumber
11:36 lb as i said above
11:36 * batman gives up.
11:36 lb it's a matter of regexp-complexity in the checker
11:36 lb i don't understand what's not to understand here :)
11:42 mattastrophe joined #mojo
11:42 lb batman: required is technically a checker, so your example is $v->check->filter->filter->check
11:43 lb i simply don't understand what you'd expect $v->check->filter; to do if not just work, instead of saying "why would you do that"
11:44 batman lb: it also sets topic(), which is required for anything to work
11:44 lb yes
11:44 batman lb: as an engineer, i'm used to forgetting about problems and just discussing solutions.
11:45 batman so... what i'm trying to say that "just because you can" is not a good reason to add functionality.
11:46 batman meaning from a real-world-problem point of view, i like bpmedley's plugin better than adding filter() to validation.
11:46 lb making check->filter->check work and make check->filter break would be a lot more work though ;)
11:47 batman since i only find it useful to filter _before_ checking. and the reason why i think that is that i compare it to coercion.
11:47 lb i don't want checks into routing, since we like mojo validation precisely because it's declarative in the controller
11:47 lb s/checks/filters/...
11:47 batman lb: i'm not discussing methods. i'm discussing the functionality and the problem it solves.
11:49 bpmedley I personally think adding filters to validation would cause side effects that might be confusing.
11:49 lb if checks could be explicitly allowed to mutate, leave it to the programmer to make a convention?
11:49 batman the problem filter solves to me is for example normalizing an IPv6 so it's ready to be stored in the database, where the user can write it in any format he/she likes.
11:49 batman same goes for phone number. but i don't want to change the phone number _after_ i have validated it. as i said: it simply doesn't make any sense to me.
11:50 lb and i accept that
11:50 batman and to me, that's what a filter does: it changes things, if not already the correct way.
11:51 batman so... maybe i want a check, which also has coercion. i'm not sure.
11:51 lb $app->validator->add_mutating_check(trim => sub {...});
11:51 batman bpmedley: i agree. (though i'm not sure)
11:52 * batman shuts up
11:53 batman i don't have anything useful to add to the discussion.
11:53 lb i'll see if i can find some time to cook up something more verbose
11:53 punter joined #mojo
11:56 bpmedley lb: Why not use a helper to add a filter, if you want to have the business logic in the controller?
11:59 lb DRY. i don't want to name the field twice if i don't have to
12:00 lb as i said, i kinda liked sri's filter-proposal from last year
12:03 batman lb: https://ssl.thorsen.pm/paste/3b446f95b07a
12:04 batman *bbl*
12:06 crux joined #mojo
12:12 lb batman: thanks, will play around with it
12:19 eseyman joined #mojo
12:23 batman so now, i'm -1 to the patch
12:24 batman and i understand now why sri changed input and ouput.
12:26 sri batman: that doesn't work with multiple values
12:26 batman sri: why not?
12:27 sri because checks are called for each value in the arrayref
12:27 lb riiight, i remember running into that last year
12:27 sri input can be {foo => 'bar', baz => ['foo', 'bar', 'baz']}
12:28 batman sri: ah! of course :(
12:28 sri for the record, i don't like my filter proposal either anymore
12:30 sri we could have done something for filtering with check return values
12:30 sri but i think that ship has sailed too now
12:31 sri should have said something earlier
12:31 lb maybe add_mutating_check?
12:31 lb (i did)
12:31 sri solution has to be elegant
12:32 sri last year was the time to figure this out
12:32 sri when we could still change validation
12:36 Grinnz pink_mist, perhaps, but i don't think it'd do a whole lot
12:36 batman sri: did you see my comment on https://github.com/kraih/mojo/issues/812 ?
12:36 Grinnz if someone wrote a (portable) interface to initgroups() though, that would be great
12:37 sri batman: yes, and i don't think you have given it enough thought
12:38 sri you generalize, instead of debunking specific use cases that have been presented here
12:39 batman sri: that's cool. no problem accepting that.
12:40 batman just had not make sure this (special?) case wasn't too special.
12:42 CandyAngel Oooo I've just realised I can use Mojo's route to sanify URLs
12:43 batman CandyAngel: what does that mean?
12:43 purl You're a nut! You're crazy in the coconut!
12:50 sri batman: there are very good arguments against upload validation
12:52 batman sri: i though the arguments were resolved.
12:54 sri i'd accept concerns like "checks get too complicated if the value can be an object", or "the code is not elegant enough"
12:54 ajr_ joined #mojo
12:55 sri your "i'm worried about more special cases in the future" is not really a concern though
12:55 sri only so many things we can put into the validator
12:56 sri actually, the only remaining thing now would be route captures, and those are just strings anyway
12:56 sri everything else would first have to be patched into $c->param() and friends...
12:57 CandyAngel batman: I'm writing a passthrough thing for a website I use and it generates URLs that point to the same place, but are significantly different
12:57 CandyAngel batman: I can make it so if it is requested to get http://somesite/randomly/different&amp;url=here
12:58 CandyAngel batman: Mojolicious can just redirect to the sane one, instead of having two separate handlers
12:58 batman sri: my main thing is that i don't see the big value. but that's purely subjective, which means i can't use it as an argument against the functionality.
12:59 sri batman: you're not considering the multiple use cases that have been brought up here
12:59 sri another valid concern would be the interaction between $c->req->is_limit_exceeded and upload validation
12:59 batman so i guess it's a bit related to "not elegant enough", when most of the checks are not usable in an upload context
12:59 sri (which is no interaction)
13:00 sri batman: no reusing my arguments!
13:00 sri if you're really concerned, you can come up with something better ;p
13:01 batman huh? why not? i'm agreeing!
13:01 * sri is not arguing for either side
13:12 zivester joined #mojo
13:45 jberger I've been thinking and if we wanted to make the validator more generic we could remove ->file and add ->instance_of('Mojo::Upload')
13:45 jberger the non-validator stuff all stays the same
13:45 jberger but the validator remains generic
13:48 punter joined #mojo
13:58 batman jberger: that's not a bad idea.
14:04 sri $validation->required('tarball')->instance_of('Mojo::Upload')->size(1, 1048576);
14:04 sri really?
14:04 sri oh right, ->size wouldn't work either
14:05 sri jberger: also, it is ->upload now, not ->file
14:08 irq joined #mojo
14:11 jberger right, size wouldn't work
14:12 jberger but if you document it as the length of a string, then its back to single purpose check and documented as such
14:13 sri i guess this might need much more discussion after all
14:13 * sri removes upload validation again
14:15 jberger well the question we first need to answer is "is the validator a generic hash structure validator, which Mojolicious uses to validate parameters" or "the validator is Mojolicious' way to validate parameters"
14:15 jberger I like what we have (had?) if the answer is the latter
14:17 sh4 joined #mojo
14:20 good_news_everyon joined #mojo
14:20 good_news_everyon [mojo] kraih pushed 1 new commit to master: http://git.io/vtCKJ
14:20 good_news_everyon mojo/master 260db33 Sebastian Riedel: remove support for validating file uploads again
14:20 good_news_everyon left #mojo
14:21 sri and i think i will step back from the discussion now
14:23 sri note that i did not change the file_field helper again, since this version is less code
14:24 batman jberger: i think it's the first, if i understand your wording correctly. it's just a hash with strings or arrays of strings in input/output
14:24 batman it doesn't know anything about $app or $c
14:29 ajr_ joined #mojo
14:30 marmez joined #mojo
14:30 marmez left #mojo
15:01 ans joined #mojo
15:11 sri i would reopen #812, but it looks like the original participants of the discussion just left 3 daus ago :/
15:11 sri s/u/y/
15:12 sri anyway, now is the time to bring up your arguments if you don't want to see upload validation to go the way of validation filters
15:34 punter joined #mojo
15:49 mattastrophe1 joined #mojo
16:15 mattastrophe joined #mojo
17:34 PryMar56 joined #mojo
17:47 trone joined #mojo
18:14 irq joined #mojo
18:49 amon joined #mojo
18:50 ajr_ joined #mojo
19:12 bin_005 joined #mojo
19:41 disputin joined #mojo
19:45 sri it gets harder to add features to mojolicious
20:00 Repaster joined #mojo
20:19 jberger joined #mojo
20:40 good_news_everyon joined #mojo
20:40 good_news_everyon [mojo] kraih pushed 1 new commit to master: http://git.io/vt88Y
20:40 good_news_everyon mojo/master 235e802 Sebastian Riedel: improve subscribers method in Mojo::EventEmitter to allow subscribers to be modified more easily
20:40 good_news_everyon left #mojo
21:09 bin_005 joined #mojo
22:04 buu joined #mojo
22:05 buu Question: if I do self->renderer->default_handler('tt'); and I have the route "example/welcome" calling $self->render; and I have two files "welcome.html.ep" and "welcome.html.tt", why does it render the .ep file?
22:09 pink_mist "The default template handler to use for rendering in cases where auto detection doesn't work, like for inline templates" <-- because auto-detection /does/ work if you have a file that ends in .html.ep
22:09 buu but..
22:10 buu So is there any way to make it 'prefer' .tt?
22:11 Grinnz_ i just do an explicit render, with handler => 'tt'
22:11 buu Also why does it say "    Registered handlers, by default only "data", "text" and "json" are already defined." ?
22:11 buu Isn't ep always defined?
22:11 Grinnz_ those are formats
22:11 buu I seem to have been confused this entire time
22:12 buu What's the difference between format and handler?
22:13 Grinnz_ the format is the .html, the handler is the .ep (for automatic rendering)
22:14 Grinnz_ actually those aren't formats, what you mentioned
22:14 buu I'M SO CONFUSED
22:15 pink_mist http://mojolicio.us/perldoc/Mojolicious/Renderer#handlers <-- honestly I'm confused too ... why are json text and data registered handlers?
22:15 Grinnz_ ok, those handlers are for doing like $self->render(data => $data)
22:15 buu In any case, my faithful ->default_handler('tt') which I've been copy and pasting for years seems to be unecessary
22:15 buu Hurray cargocults
22:16 Grinnz_ there's maybe some conflict in terms between renderer handlers, and template handlers
22:17 Grinnz_ i might just be missing the connection, too
22:17 buu $renderer   = $renderer->default_handler('ep');
22:18 buu Handler is clearly not json..
22:18 buu Which ok that makes sense
22:18 buu Except ep is always registered?
22:19 sri no, ep is from a plugin, which just happens to be loaded automatically
22:19 purl okay, sri.
22:19 Grinnz_ ah!
22:19 sri while data, text and json are built into the renderer
22:22 buu This seems like a fine distinction
22:22 Kogurr joined #mojo
22:24 sri hahahaha... so Scalia's Tears is now a drink
22:24 Grinnz_ lol
22:26 sri Malort, Combier, apple bitters and a bit of salt
22:26 sri gotta try that
22:41 real joined #mojo
22:44 lluad joined #mojo
22:46 ajr_ joined #mojo
22:46 jberger Yum
22:47 howitdo joined #mojo
23:26 frederico joined #mojo

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary