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

IRC log for #mojo, 2016-01-05

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

All times shown according to UTC.

Time Nick Message
00:29 punter joined #mojo
00:43 orev joined #mojo
00:53 bpmedley joined #mojo
01:14 damaya joined #mojo
02:12 gryphon joined #mojo
02:12 kaare joined #mojo
03:06 noganex joined #mojo
03:49 bpmedley joined #mojo
04:06 damaya joined #mojo
04:42 jontaylor joined #mojo
04:55 voldemortensen joined #mojo
06:20 damaya joined #mojo
06:36 * batman tries to change to having the POD in the bottom of the file...
06:36 batman (good morning)
06:36 batman the reason why i had it in-between-the-code was that i think it was easier to read the doc and then the code
06:37 batman but i found myself doing some formatting that makes it inconsistent.
06:37 batman so...
06:37 batman i wonder how people (who have the pod in the bottom) jump from method to doc easily.
06:37 batman (sorry for the non-mojo question)
06:37 batman i'm using vim
06:49 melo joined #mojo
07:01 dod joined #mojo
07:07 dod joined #mojo
07:09 damaya joined #mojo
07:41 trone joined #mojo
07:49 janus joined #mojo
07:51 melo joined #mojo
08:03 CandyAngel batman: I use Leo, so I have the method and documentation in nodes next to each other, which is cloned under another node for writing it to the file in the respective place
08:07 batman ok. thanks
08:09 osfabibisi joined #mojo
08:21 AndrewIsh joined #mojo
08:22 Vandal joined #mojo
08:32 osfabibisi joined #mojo
08:41 sue joined #mojo
08:46 berov batman: I split my screen. And I have to admit I prefer POD at the bottom too :)
08:47 Adura My code is self-documenting.
08:47 berov batman: I also usually add one line comment on what the method does just before the name of the method
08:48 berov Adura: that also is a must
08:51 kes joined #mojo
08:54 melo joined #mojo
08:54 batman Adura: haha, yeah... :)
08:55 batman berov: not sure if i want that... then i have to keep the doc in sync :/
08:55 berov batman: do you often change what the method does once you create it?
08:56 batman berov: not sure actually...
08:57 berov :)
08:58 berov I found that if we keep to PBP we do not need to update the methods' documentation (much)
09:04 batman i just made this https://gist.github.com/jhthorsen/31b8f02407957465fd05 which does what i want
09:04 batman (at least is looks like it)
09:14 berov I do not use vim, but may be it will worth it to contribute this to the Perl support project for VIM
09:20 damaya joined #mojo
09:21 vytas joined #mojo
09:36 damaya joined #mojo
09:40 jontaylor joined #mojo
09:55 CandyAngel I put my POD in a separate file.. I think I'm part of a pretty small group in that regard :P
09:59 binlei joined #mojo
09:59 binlei hello
09:59 binlei Does anyone use kafka in mojolicious?
09:59 binlei any idea how to deal with non-blocking?
10:10 berov joined #mojo
10:17 talexb__ joined #mojo
10:17 CandyAngel Ooo.. maybe I can leverage Mojolicious with my inventory files. That would be cool..
10:18 CandyAngel Convert the YAML to XML and use the CSS selectors for grepping.. could work
10:20 sugar joined #mojo
10:28 sue joined #mojo
10:28 MartinR joined #mojo
10:57 melo joined #mojo
11:08 damaya joined #mojo
11:52 neilhwatson joined #mojo
11:59 bpmedley_ joined #mojo
12:17 CandyAngel Okay, I got something that kinda works
12:30 batman berov: i just sent an email to one of the contributors of https://github.com/vim-perl/vim-perl (thank you)
12:31 berov batman: \o/ great :)
12:35 punter joined #mojo
12:42 janus joined #mojo
12:44 asarch joined #mojo
12:48 jkramer joined #mojo
12:48 jkramer Ahoy
12:49 jkramer I just made this: https://gist.github.com/jkramer/087732a66c256fa4fca3 - does anyone think it'd be worth it putting this on CPAN as proper module or is it to trivial?
12:52 CandyAngel jkramer: If you are going to maintain it, why not? Let's people be lazy!
12:52 CandyAngel Lets*
12:54 melo joined #mojo
12:54 jkramer Well true. I'll prepare and put it up when I have some spare time
12:56 CandyAngel Yay \o/
12:57 CandyAngel Thank you :)
12:58 jkramer :)
12:59 jkramer sri: Do you mind me putting this in Mojo::UserAgent:: or do you have any other objections?
13:12 batman jkramer: i made this: https://metacpan.org/pod/Mojo::UserAgent::DigestAuth maybe it can be an idea?
13:12 batman not sure if i've done it right though...
13:13 batman jkramer: i don't think you will cause any name collisions, so you it's fine by me.
13:13 batman maybe jberger has some input?
13:14 batman jkramer: you might have the option of doing "once()" instead of "on()".
13:15 batman on() will "mess up" any future requests, so if someone does that on $app->ua, they will get into trouble
13:19 jkramer batman: Good point, I think I'll add hook_once or something like that in addition. People can also sign their stuff manually of they need more control: $oauth->sign_request($tx->req)
13:20 batman also, the use strict and new() is not very "mojo". do this: use Mojo::Base -base;
13:21 jkramer Oh also ->new takes a host parameter and only requests to that host will be signed, so I think it's relatively safe to 'permanently' hook into app->ua, even with several instances of the oauth addon
13:21 batman jkramer: check this out: https://metacpan.org/pod/Mojo::Base#DESCRIPTION
13:21 kaare joined #mojo
13:22 batman hm... that sounds a bit too complex imo. i would just do once() and drop the "host" parameter
13:22 batman (my humble opinion)
13:23 jkramer Yeah I didn't really think it through yet with other users in mind, I just put it together real quick because I needed it :)
13:24 batman jkramer: that's cool :)
13:24 batman jkramer++ # making stuff
13:25 batman also... how important is it that nonce is random? is it critical for the security?
13:26 taichi joined #mojo
13:26 batman the synopsis could also be: my $tx = $oauth->hook($ua)->get('https://test.com/something-secret');
13:27 batman not sure if that makes it any cleaner...
13:27 jkramer batman: Not necessarily random, but unique to each request. At least I haven't seen an oauth implementation yet where it wasn't random, and I'm sure it's relevant to security
13:27 batman no... that will not do what you want. another reason to use once(): make sure the event is only applied once.
13:28 batman right now, it's easier to run sign_request() multiple times on the same $ua
13:28 jkramer Maybe: say $oauth->sign($ua->get(...))->res->body
13:29 batman that won't work, since the $tx passed on to sign() will be completed
13:29 jkramer Meh right
13:30 jkramer Thought there was some laziness envolved
13:30 batman :)
13:31 batman i think maybe i would do $oauth->sign_next_request($ua); $ua->get(...);
13:31 jkramer Yup, just thought the same thing
13:31 jkramer Well, it's basically the same as hook_once as suggested above but with a better name :D
13:31 batman you can have sign_all_requests() as well, but then at least the method is more explicit.
13:31 jkramer Yep
13:31 batman yeah.
13:32 batman "hook" doesn't really describe what it does, so that's why i suggested a new name
13:33 batman did you catch the "use Mojo::Base -base" comment?
13:34 jkramer Yep, already changed module, I'll post another gist later for review :)
13:34 batman sweet!
13:35 batman hope my feedback is constructive. let me know if it isn't :)
13:35 jkramer One more idea: Let the user do: $ua->on(on/once => $oauth->sign_callback)
13:36 jkramer batman: No worries, indeed very helpful :)
13:36 batman cool
13:36 batman yeah! that's probably even better :)
13:36 batman $ua->on(on/once => $oauth->sign_callback)
13:37 batman let's you chain it as well: $ua->tap(once => $oauth->sign_callback)->get("http://example.com")->res->body;
13:38 batman *lets
13:39 batman i think that's the best idea jkramer. the api can't get much simpler than that :) (just one method)
13:39 jkramer Yup, I like it too :)
13:40 batman please post the updated gist once you've updated it
13:41 batman ...you might also turn add attributes: has [qw( consumer_key consumer_secret signature_method )] => "";
13:41 batman s/turn//
13:42 jkramer Yeah, did that already
13:42 batman :)
13:48 lluad joined #mojo
13:54 binlei joined #mojo
13:59 melo1 joined #mojo
14:00 sh4 joined #mojo
14:04 jberger I haven't really done enough oauth to really think about flow
14:09 Sound joined #mojo
14:09 melo joined #mojo
14:13 batman jberger: what about the name?
14:16 jkramer Updated the gist: https://gist.github.com/jkramer/087732a66c256fa4fca3
14:26 batman jkramer: since the method is called "sign_callback" i would just return a callback and not "start"
14:27 batman but that's just a minor
14:28 batman maybe i would rather return("start" => sub {}) unless $res; from sign_request()
14:28 batman nah.. not sure if that makes it any better
14:29 batman $ua->on(start => $oauth->cb); # might be shorter... not sure :)
14:29 jkramer Yeah I had the same idea, but I think that'd make stuff somewhat confusing
14:30 batman i think the module is a lot cleaner now :)
14:32 jkramer Not sure if tap(once => start => $oauth->cb) is better than just tap(once => $oauth->cb). I mean is there a case where you'd use anything but start?
14:35 batman i agree. nevermind my last comments :)
14:35 batman i think i would keep it as is
14:35 jkramer How about cb for just the callback and ->event for start => cb?
14:36 jkramer But I don't think anyone would ever use ->event anyway :D
14:37 jkramer I like ->cb though, it's nice and short and since it's the only method you'd ever use there isn't much room for confusion
14:39 binlei Does anyone use kafka in mojolicious?
14:44 sue joined #mojo
14:59 gryphon joined #mojo
15:10 melo1 joined #mojo
15:12 voldemortensen joined #mojo
15:16 voldemortensen joined #mojo
15:16 batman jkramer: i like event() better than cb().
15:16 batman "on event" sounds better than "on cb"
15:30 Lee joined #mojo
15:42 cpan_mojo Mojolicious-Plugin-MountPSGI-0.11 by JBERGER https://metacpan.org/release/JBERGER/Mojolicious-Plugin-MountPSGI-0.11
15:48 Grinnz_ jkramer: you might be interested in this project of mine https://github.com/Grinnz/WWW-OAuth
15:48 Grinnz_ the intent is a bit more lowlevel than what you're doing
15:49 Grinnz_ i haven't written the oauth2 part yet or decided on the exact overall api
16:00 bpmedley joined #mojo
16:04 batman Grinnz_: that looked quite complicated. what is the reasoning behind the code?
16:05 batman was a bit hard to get/follow without any synopsis :/
16:06 Grinnz_ to abstract the "oauth authorizing" step to be usable for various useragents
16:07 Grinnz_ basically i want something to use instead of Net::OAuth and similar for OAuth2, which i can use with HTTP::Tiny or Mojo::UA
16:08 Grinnz_ the meat right now is in https://github.com/Grinnz/WWW-OAuth/blob/master/lib/WWW/OAuth/Authorizer/OAuth1_0.pm -- the HTTPRequest objects provide an abstract interface for it to modify the request with the oauth parameters
16:15 voldemortensen joined #mojo
16:20 Grinnz_ it's intended to just do the modifying step, so it doesn't get in the way of doing the actual requests synchronously or asynchronously
16:22 Sound Hello!  This is probably a FAQ, but forgive me: can I dispatch a request to another controller from an action handler?
16:23 Mattjes joined #mojo
16:23 Mattjes Hello
16:23 jberger Sound: of course there are ways to do that, but its a code smell
16:24 Mattjes how can i find two css-class with one find?
16:24 jberger it means that you have logic that should be extracted out, probably either into model logic or helpers
16:24 jberger Sound: ^^
16:24 Mattjes $details_raw->find('.hell, .dunkel')->each dont work
16:25 Grinnz_ Mattjes: sure it does
16:25 Grinnz_ https://metacpan.org/pod/Mojo::DOM::CSS#E-F-G
16:25 Mattjes hmmm
16:25 Mattjes one moment plz
16:25 Sound jberger: suppose I have a controller/action tied to '/objects/:id', that detects what type the object is, and then decides to route the request to a more specific controller
16:26 Sound jberger: it's a fairly large and complex application, so having sub-controllers might make sense
16:27 jberger Sound: that sounds more like an "under"
16:28 Sound jberger: but post-under routing does not take place according to URL/HTTP rules.  It's based on object properties
16:28 Mattjes Grinnz_: Its works now - i had a mistake here
16:28 Mattjes thank you
16:31 jberger Sound: but you can decided to traverse into a set of child routes or not
16:31 jberger which is all you need
16:32 Sound jberger: how can I dispatch multiple requests for the same URL to different controllers according to, say, a database query?
16:33 jberger Sound: make a query and return either 1 or 0, same as other unders
16:33 batman Grinnz_: sounds like what jkramer made :/
16:34 Sound jberger: that looks like boolean logic, doesn't work if I have more than two types
16:34 jberger Sound: no, each under returns 1 or 0 if the dispatch should continue down that tree
16:34 Grinnz_ batman: it could fill that role, which is why i mentioned it ;)
16:35 batman Grinnz_: but the role is already filled..?
16:36 batman sorry... i think i'm missing out on something here :/
16:36 Grinnz_ filled by?
16:36 Sound jberger: suppose my object 1 is an apple, and object 2 is a banana.  I want /objects/1 to be handled by my MyController::Apple and /objects/2 to be handled by MyController::Banana.    Ideally, I would map the URL to MyController and it would then re-route the request to the correct subcontroller
16:36 Kogurr joined #mojo
16:36 batman Grinnz_: Net::OAuth
16:36 batman the request is done by ua, but Net::OAuth is used to prepare the correct request..?
16:36 batman s/ua/mojo ua/
16:37 batman that's what it looks like to me, from the gist
16:39 Grinnz_ it's using Net::OAuth to apply the header to the Mojo request, yes... but Net::OAuth requires LWP because it normally manages the useragent for you (and it also doesn't do oauth 2)
16:39 batman so your module will do the same thing, but without requiring LWP (if we only speak about oauth1)
16:39 Grinnz_ basically, yes
16:40 batman ok. thanks
17:47 sue joined #mojo
17:55 Grinnz_ Sound: i dont think theres any real native way to do something like that, but there's no reason you can't make your own modules with functions that take the common controller object
17:55 Grinnz_ or helper methods, is another way
18:01 jberger yeah, I though it would traverse back out to the next subtree, but I can't make that work
18:07 PryMar56 joined #mojo
18:11 gryphon joined #mojo
18:16 batman Sound: i would create models which you can call methods on, dependent on the input
18:17 batman or create objects of the correct model class.
18:32 Sound Grinnz_, batman: yeah, thank you. There are several options, none of which is ideal. Model classes are not good because I don't have access to controller stuff from there (params, render(), session, stash etc.).  I think I will create some custom classes which take the Mojolicious controller as one of the arguments
18:33 batman i don't think you need that. it took me a while, but i'm very glad i never send $c to my models anymore.
18:33 batman "separation of concerns"
18:34 Grinnz_ what he's talking about aren't really models though.
18:35 Grinnz_ i.e. it may render differently for different items
18:35 Sound Exactly, that's why I'm not going for models.  I need to distinguish *controller* logic, not model logic
18:37 batman i don't think you need... but it's impossible for me to tell for sure without seeing/knowing the project
18:37 batman "think": based on experience.
18:37 Sound batman: yeah, difficult to discuss without details on the project, as always :)
18:39 batman i would however advice you to rethink the solution.
18:40 batman or actually: just try your best to come up with an alternative structure.
18:40 batman much easier to know what is right if you have two solutions.
18:41 Sound batman: being able to redirect to another controller/action would sound so natural to me :)
18:41 batman doesn't make it right :(
18:42 batman i used to think the same. i actually implemented the functionality in Catalyst.
18:43 batman it turned my code into a complete mess :/
18:47 dod joined #mojo
18:50 Sound batman: my current situation is a traditional MVC approach, with a single controller/action method handling everything for '/objects/:id'.  Since objects have different types and other properties which lead to different templates and logic, my controller/action method is divided into conditional blocks.  However it's huge.  First step is to move everything to private methods of the same controller (thus calling $self->"_handle_${type}").  But
18:50 Sound would look cleaner to me if each $type had an actual separate controller class
18:51 batman why don't you have /:type/:id ?
18:52 batman doesn't sound right if id 1 is a banana and id 2 is a car :/
18:52 mspo or routes for each one
18:52 mspo less typing since it alread sounds like a static list of object types
18:53 batman s/:type/:controller/
18:53 Sound batman: suppose it's an e-commerce website (it's not).   1 can be a banana and 2 can be a car, definitely.  That wouldn't be wrong at all :-)   And exposing a property in URL doesn't look very clean
18:53 Sound An object might change type, but why should it change URL?  It would break REST
18:54 batman that's wrong. an resource (url) /should/ describe the object.
18:54 batman a banana can't become a car. sorry. at least not in 2016 :)
18:54 batman and... even if it could, the url should change
18:54 * nic buys up cheap bananas just in case
18:54 batman nic :D
18:54 jberger no, but I can imagine things that might work
18:55 jberger vehicles/sports cars/work vans/etc
18:56 batman so... if "/car/42" suddenly turns into a "/vegetable/42", then it's just right since the ::Vegetable controller should then handle the logic
18:56 batman on the other hand, if "42" is a car and you pass it to "/vegetable/42" it could simply result in a 302 redirect
18:56 batman or a 400 bad request.
18:57 batman depends on how you want to communicate back to the user of your application
18:57 genio 500 internal server error.  nothing useful for you!
18:57 batman "400 bad request: Sorry, your banana is a <a href="/car/42">car</h2>!"
18:58 genio <a></h2>  heh
18:59 batman and if you need to handle legacy issues with "bad" urls, then just do 301 redirect on "/:id"
18:59 Sound batman: I don't really want to hard-code those types in route definitions
19:00 batman that's why you can use /:controller/:id instead
19:00 batman it will use the first placeholder to figure out which controller to dispatch to
19:00 batman $r->any("/:controller/:id")->to("#handle_weird_object");
19:01 Sound batman: but that forces me to expose those names as URLs, and gives me no power in controlling that mapping
19:01 batman handle_weird_object = handle_weird_object() = name of action. :controller is variable.
19:01 Sound batman: also, AFAIK controllers are not namespaced so that looks quite dangerous
19:02 batman they are very much namespaced.
19:02 batman Sound: i give up.
19:02 Sound batman: suppose I have a "Login" controller, or "Auth", or whatever, and someone creates a "login" object type... which one will be chosen?
19:03 jberger Sound: remember Controllers are not Model classes
19:03 batman Sound: you're inventing problems to brute force your initial idea. i can't continue in a constructive way :(
19:03 batman sorry.
19:04 Sound batman: I just want to understand your proposal.   How do I tell $r->any("/:controller/:id") to look for :controller in a given controller namespace?
19:05 batman Sound: it won't be /Some::Controller::Class/42. it will be /user/42, which again will be looked up in the MyApp::Controller:: namespace
19:06 Sound batman: exactly.  Which means that my object types and controller names (including "auth", "user" and whatever) share the same namespace as they would clash
19:06 jberger Sound: I don't think any of us recommend using :controller (or :action) in patterns except perhaps for simple prototyping
19:07 batman Sound: it won't class. you can either limit the values of :controller or simply dispatch to an action that doesn't exist in any of the other controllers
19:07 Sound I really think that object types (or any other model property) != controller names
19:07 batman *clash
19:09 batman Sound: but they do make perfect sense in an url. use the information!
19:09 batman http://example.com/42 <--- that is _not_ at all an informative url.
19:10 batman http://example.com/car/42 # a bit better
19:11 batman http://example.com/car/volvo_850 # a lot more informative
19:13 Sound batman: I definitely agree, but my point here is that I feel lack of flexibility.  It's like saying that Python programs are better because it enforces indenting.  :-)
19:14 Sound my controller/rendering logic might depend on multiple properties, not just one.   And suppose my controller has different logic according to week day (first example that comes to my mind), or an external variable;  I currently have blocks like "if ($today eq 'Monday') { ...}" that I'd just like to split for code cleanness.
19:15 Sound anyway, I understand there's no way to redirect to another controller, so I'll figure out how to deal with the available tools.  Not trying to convince anyone :)
19:15 batman (general/flexible code)--
19:16 batman yeah... so i got an solution for you...
19:16 batman https://metacpan.org/pod/Role::Tiny#apply_roles_to_object
19:16 batman i also used to think that was an awesome idea ^^
19:17 batman well... it just made my code harder to understand, read and change.
19:17 batman s/an/a/
19:17 Sound batman: I usually use Moo and Moo::Role
19:18 batman but do you apply roles to an object?
19:18 Sound batman: ah, to a single instance?  Never did that, doesn't look that nice...
19:19 batman this means that you can have sub Controller::foo { my $c = shift; Role::Tiny->apply_roles_to_object($c, $c->_calculate_roles_from_input); $c->call_method_from_a_role }
19:19 batman it's a complete mess imo
19:19 Sound batman: ouch.  That's a solution.  Not sexy at all :P
19:20 batman (sounds exactly like what you want though)
19:20 jberger note that that's what's under the hood of Test::Mojo::WithRoles
19:20 batman jberger: but it's not dynamic in the same sense.
19:20 batman i'm not against roles.
19:20 Sound dynamic roles are... ugh...
19:32 Sound Anyway, thanks for discussing. Much appreciated. I'm always struggling for cleaner code, so this is more a "How do I write it nicer" instead of "How do I do it".  -> BBL
19:53 _dave_ joined #mojo
20:03 zivester joined #mojo
20:09 berov1 joined #mojo
20:38 voldemortensen1 joined #mojo
20:42 voldemortensen joined #mojo
20:43 melo joined #mojo
20:50 jb360 joined #mojo
20:55 Sound_ joined #mojo
21:05 sugar joined #mojo
21:19 cpan_mojo Net-Easypost-0.17 by MCMILLHJ https://metacpan.org/release/MCMILLHJ/Net-Easypost-0.17
21:28 cpan_mojo Net-Easypost-0.18 by MCMILLHJ https://metacpan.org/release/MCMILLHJ/Net-Easypost-0.18
23:07 zivester joined #mojo
23:20 PopeF joined #mojo
23:25 PopeF joined #mojo
23:45 punter joined #mojo
23:55 jberger joined #mojo

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