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

IRC log for #mojo, 2017-05-22

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

All times shown according to UTC.

Time Nick Message
00:22 dboehmer joined #mojo
01:17 tchaves joined #mojo
01:17 aborazmeh joined #mojo
01:43 VVelox joined #mojo
01:54 ilbot2 joined #mojo
01:54 Topic for #mojo is now ???? nom nom | http://mojolicious.org | http://irclog.mojolicious.org | http://code-of-conduct.mojolicious.org
02:05 noganex_ joined #mojo
02:49 PryMar56 joined #mojo
02:58 punter joined #mojo
04:04 dboehmer_ joined #mojo
05:14 inokenty-w joined #mojo
05:37 ashimema I'd say that'smore akin to json-schema than OpenAPI jberger.. json-schema is a core dependancy of OpenAPI though ;)
05:37 ashimema and of course.. because of ::OpenAPI there's the JSON::Validator module thanks for batman
05:38 ashimema never heard of joi before.. wonder how it differs from json-schema.. any reason you chose that one to use as an example sri?
05:40 dod joined #mojo
05:45 dod joined #mojo
06:03 punter joined #mojo
06:11 mattp_ joined #mojo
06:22 dod joined #mojo
06:41 Vandal joined #mojo
06:42 AndrewIsh joined #mojo
06:47 AndrewIsh joined #mojo
07:04 batman sri: what does "only validation" mean?
07:33 sri batman: i mean we'd only support validation in core
07:33 sri ashimema: because joi is incredibly popular
07:35 trone joined #mojo
07:35 dod joined #mojo
07:38 karjala_ joined #mojo
07:39 batman sri: what else does json-validator do..?
07:39 sri ?
07:41 * ashimema wonders why he'd never heard of joi
07:41 batman guess i misunderstood your response to jberger...
07:41 ashimema oh well.. I'm committed to json-schema now for better or for worse.
07:42 ashimema OpenAPI is more than validation (as in it's an api modelling tool, so you can construct routes etc from it).. but JSON::Validator is simply validation against schemata
07:46 ashimema joi looks more in code oriented whereass json-schema seems to be more about sharing schema documents which yuo can validate against
07:47 dod joined #mojo
07:48 ashimema So I can now see why you point to it as an example of an in app validator.. though json-schema could be used with data sections pretty trivially
08:48 rshadow joined #mojo
09:10 batman sri: thinking about doing something like this: https://github.com/jhthorsen/json-validator/blob/joi/lib/JSON/Validator/Joi.pm
09:11 batman just need more utility functions like "email"
09:12 batman s/functions/methods/
09:13 * ashimema is interested by this..
09:16 batman think i will rename joi() to jv() and make JSON::Validator export it...
09:16 ashimema :)
09:20 sri yes, like that ;p
09:20 sri well, guess i won't be doing that after all then
09:20 sri jv() seems reasonable
09:21 batman do you have time to give me feedback before i release it?
09:22 sri just for a quick look, but no in depth feedback
09:22 batman i wonder what the class should be called... i kind of like "joi", since then it might show up if people know the javascript library
09:22 batman sri: ok. i've marked it as experimental, so i can fix it later :)
09:22 sri i mean, the example looks pretty great https://github.com/jhthorsen/json-validator/blob/joi/lib/JSON/Validator/Joi.pm#L110-L121
09:23 batman i think "joi->object->keys" is a lot to write, so i will make it so if you just provide a hash, it will understand that it's the same.
09:33 coolo joined #mojo
09:55 ashimema batman++
10:28 prg joined #mojo
10:35 batman sri: the API is limited to what JSON-Schema can do though... not sure if I will support the complete joi API.
10:36 batman The API = what I'm doing
10:47 haarg batman: have you seen the indexing issues with Mojo::mysql?
10:48 haarg *pause indexing
10:49 pink_mist what issues are those? (just curious)
10:49 haarg Mojo::myql 1.02 is still indexed
10:49 pink_mist https://metacpan.org/release/Mojo-mysql leads to 1.03 0_o
10:50 haarg and the copy of 02packages i'm looking at has 1.03 listed for some of the packages, so it isn't just a late mirror
10:50 haarg metacpan's idea of latest doesn't perfectly replicate what PAUSE thinks
10:50 pink_mist oh, ok
10:51 batman haarg: no, i haven't. how can i fix it?
10:52 haarg https://pause.perl.org/pause/authenquery?ACTION=reindex should be able to reindex here
10:52 haarg but you might want to look at the emails pause sent to see if it says why it didn't index properly
11:00 dod joined #mojo
11:31 batman if anyone is interested in joi/validation: https://github.com/jhthorsen/json-validator/pull/63
11:31 batman haarg: better now?
11:33 tchaves joined #mojo
11:34 batman hm... doesn't seem like it :/
11:35 batman haarg: i got "The PAUSE indexer could not store the indexing result in the DB due the following error: Lock wait timeout exceeded" yesterday, and it does not seem to reindex
11:35 batman haven't gotten any new email, and it was scheduled to complete 30 min ago
11:36 batman oh. maybe i'm not too good with timezones: maybe it's scheduled to complete in 30 min :P
11:36 batman i'll give it some more time
11:37 haarg batman: i'd give it some more time.  i'm assuming it was a transient error yesterday.
11:37 batman http://dogfood.convos.by/paste/c91ab90964479c498d53/149545306873033
11:38 batman ok
11:48 rshadow joined #mojo
11:52 gregf_ joined #mojo
12:12 haarg batman: on an unrelated subject, i noticed you have a few dists doing this: https://metacpan.org/source/JHTHORSEN/App-docsisious-0.08/t/docsisious.t#L7
12:13 haarg which is going to break in the future, as it relies on . being in @INC
12:14 haarg running the paths through rel2abs before passing them to do may be the easiest solution
12:20 batman haarg: i don't understand. are you saying that $PWD won't be the root of the dist?
12:21 haarg do searches @INC to find the files it loads
12:21 haarg . (aka $PWD) is being removed from @INC
12:22 haarg so do will not be able to find files relative to the current directory, unless you use a path like ./blah
12:22 batman oh. that's funny... learning new stuff :) i thought `do $file` was the same as `eval path($file)->slurp`
12:23 batman sort of... as in how it resolved the file
12:23 haarg i think most people expect it to work that way
12:23 batman i only changed all my test files to do `use lib '.';`. Didn't think about `do()` was affected the same way
12:24 haarg use lib '.' is an alternate solution
12:24 batman yeah, but i only did it, when i had `use t::Helper;`
12:24 haarg but you don't appear to be doing that in the example i linked
12:24 batman i'll fix it tomorrow night
12:25 batman haarg: https://github.com/jhthorsen/json-validator/blob/master/t/jv-allof.t#L1-L2 <--
12:25 haarg note that do("./script/docsisious") will work, or do(rel2abs("script/docsisious"))
12:26 haarg but not do(catfile qw(. script docsisious)), because it will "helpfully" strip off the leading ./
12:27 batman awesome! i will change to Mojo::File then
12:27 batman haarg++ # thanks
12:27 batman Grinnz++ # thanks for helping out with Mojo::mysql
12:28 batman karjala_: sorry for leaving on friday. had a date :/
12:29 haarg Mojo::File also strips off a leading ./
12:29 batman i will do: `do(path(qw(script docsisious))->to_abs)`
12:31 karjala_ batman, it's ok1
12:31 karjala_ !
12:31 skech1080 joined #mojo
12:32 batman \o/
12:39 jabberwok joined #mojo
13:09 aborazmeh joined #mojo
13:17 gizmomathboy joined #mojo
13:21 irqq joined #mojo
13:24 gizmomathboy joined #mojo
13:31 kaare joined #mojo
13:36 Pyritic joined #mojo
13:36 elik joined #mojo
13:56 Pyritic joined #mojo
13:58 rshadow joined #mojo
14:03 PryMar56 joined #mojo
14:09 mcsnolte joined #mojo
14:17 maschine joined #mojo
14:24 perlpilot joined #mojo
14:47 sri is ibm in financial trouble?
14:48 sri they just went full yahoo and killed remote work Oo
14:58 jberger hmmmmmm
14:58 coolo that their marketing is reducing home office is news from march. any newer development?
14:59 coolo or even february: http://www.silicon.de/41640402/ibm-schafft-homeoffice-ab/
15:00 coolo interesting. So it was announced in feburary, but became mainstream news end of march and now some newspapers are warming it up :)
15:12 marty joined #mojo
15:16 jberger Trump is out of town?
15:20 sri i just saw this popping up on my twitter stream https://www.inc.com/geoffrey-james/ibm-just-committed-cultural-and-creative-suicide.html
15:21 coolo jberger: german spiegel had head lines that Trump ordered a steak with ketchup - the world is good
15:25 nic The thing I found most funny about his prep for this foreign jaunt was his team's difficulty getting him to read the 2-page briefing they'd put together.  There was a suggestion he doesn't read anything and spends most of his time watching tv
15:29 ribasushi joined #mojo
15:31 coolo nic: as most people do in their 70ties :)
15:33 nic :)
15:34 sri wonder what we'll be doing when we are that age
15:36 sri watching netflix and playing fancy vr games i suppose
15:39 CHYC Something presidential no doubt.
15:51 stryx` joined #mojo
16:06 Dandre joined #mojo
16:16 sh14 joined #mojo
16:35 kamyl hey guys, how can I get wss:// URLs generated from mojo using to_abs method in an app behind nginx with SSL termination? Mojo is aware that it's running behind proxy, is there some header I need to set to get that automagically done?
16:49 rshadow joined #mojo
16:52 Pyritic joined #mojo
16:56 pink_mist how did you make mojo aware that it's running behind a proxy?
16:56 pink_mist because that's how you do it.
16:57 kamyl -p parameter as per --help
16:57 pink_mist did you perhaps mean that you set MOJO_REVERSE_PROXY=1 environment variable when you started mojo?
16:57 pink_mist because that's how you do it, not any -p thing
16:58 kamyl I didn't do that, I thought that -p would be enough, perhaps I misunderstood it, I'll follow your suggestion
17:00 pink_mist oh, actually, it may be that -p should be working if you're using mojo daemon to run it ... (I tend to use hypnotoad though)
17:00 kamyl I'm using prefork
17:01 stryx` joined #mojo
17:03 kamyl unfortunately websocket URL is still getting generated as a ws:// with MOJO_REVERSE_PROXY=1 set
17:05 pink_mist odd ... can you show code?
17:06 kamyl var ws = new WebSocket("<%= url_for('websocket_method')->to_abs %>");
17:07 pink_mist and you're sure you're accessing the page via https when you're testing? :P
17:07 kamyl yes :)
17:07 pink_mist damn, that was the last thing I could think of :/
17:07 kamyl without ssl it works perfectly
17:08 pink_mist it ought to work just fine already
17:09 kamyl is there perhaps some standard way to tell mojo to pick some header, check its value and based on its content/existence set certain url scheme?
17:09 pink_mist you're sure it isn't something like your browser caching the page, so any changes you're making doesn't show up? :P
17:10 stryx` joined #mojo
17:10 pink_mist kamyl: yes, the standard way is to set MOJO_REVERSE_PROXY=1 and the X-Forwarded-Proto header to https
17:11 kamyl ha, this header, I'm not setting it up, not sure if my nginx config has this set
17:11 Grinnz https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Nginx
17:11 Grinnz the appropriate X-Forwarded-For and X-Forwarded-Proto headers to set in nginx are there
17:13 Grinnz the only thing the reverse_proxy or MOJO_REVERSE_PROXY settings do is cause mojo to check for those headers
17:14 Grinnz (it cannot by default, as it would be a security issue to check those headers when not actually behind a proxy)
17:14 kamyl setting those two headers did indeed the trick, thanks for help pink_mist and Grinnz!
17:14 kamyl I'm embarassed to not have found this info
17:14 Grinnz the cookbook has lots of helpful deployment info
17:16 kamyl it does indeed, I used quite some of them already, just not sure why duckduckgo didn't point me there during my searches
17:19 kaare joined #mojo
17:51 Janos joined #mojo
17:51 trone joined #mojo
18:18 zivester joined #mojo
18:22 Pyritic joined #mojo
18:47 dod joined #mojo
18:49 irqq joined #mojo
19:02 kgoess is before_dispatch the appropriate place to do a setlocale() ?
19:04 preaction i'd do that in startup
19:05 kgoess it's different for each request though
19:05 kgoess that's why I was asking, if the out-of-order nature of the mojo event loop would make that before_dispatch the wrong place
19:05 Grinnz kgoess: that's impossible to manage in a mojolicious application. requests can always run simultaneously
19:06 kgoess ok, right. so I should only do it in the code that's doing the rendering and needs the locale set
19:06 Grinnz that would be a way to do it yes
19:06 Grinnz as long as the rendering code doesn't do anything async too
19:06 kgoess right
19:13 punter joined #mojo
19:13 preaction this sounds very bad
19:26 stefan_ Does anyone have any suggestions on what I should read / understand better with respect to using weaken()?  I'm finding a lot of code in Mojolicious and Mojo apps and plugins that use weaken() and now sri just fixed a memory leak bug with weaken.  How to know how and why to do that?  (I suspect apps that I'm writing are leaking memory but I don't know how to figure out when or where.)
19:28 preaction stefan_: https://perldoc.perl.org/perlref.html#Circular-References to start maybe?
19:31 jberger stefan_: you need to learn about how reference counting works wrt garbage collection
19:31 stefan_ Thanks, preaction!  How do I identify the circular reference in sri's bug fix: https://github.com/kraih/mojo/blob/d69b981e1d20dacfaca642e335d5672df7a87e52/lib/Mojo/IOLoop/Client.pm#L167
19:32 stefan_ Like, that doesn't look the same as the circular references in the perlref guide.
19:32 jberger and how closures can make that worse, especially when callbacks are common
19:32 Pyritic joined #mojo
19:33 preaction stefan_: lines 170 and 171 can create circular references through the callback subs. or they could just hold on to the $self reference for longer than needs to be (because $tls survives)
19:33 stefan_ Perfect, so 170 and 171 are the memory leak, not 169?
19:34 preaction not 169, no
19:36 stefan_ So what I am looking for is when I define a variable outside of a callback and let that callback use it lexically scoped?  (Sorry for my poor description.)
19:36 preaction no. if you want to know if you're leaking memory, use Test::LeakTrace or Devel::Cycle
19:37 stefan_ Ah good!  Thank you!
19:42 elik joined #mojo
20:02 elik joined #mojo
20:27 sri stefan_: it will always be tough, i'm still having problems tracking down leaks all the time
20:29 stryx` joined #mojo
20:44 simbabque can I do chained routes in mojo?
20:45 simbabque so that I can have /foo/:id/bar and /foo/:id/baz both use the same piece of code to do the /foo/:id part, and then attach the actions for /bar and /baz to it
20:46 preaction you can do under() to achieve that
20:46 simbabque and in the /foo/:id part e.g. load the $id from the db and put the obj in the stash
20:46 simbabque ah, I was doing my $foo = $c->any('/foo/:id')->to...
20:47 simbabque and then $foo->get('/')->...
20:47 simbabque I'm used to this thing being called a chain like in catalyst
20:48 simbabque preaction++
20:48 simbabque thank you, that works like a charm :)
20:48 simbabque I can even do $foo->get('') to get just '/foo/:id'... I was expecting that to fail for some reason
20:48 preaction you could also just use a helper/controller method and not get the routing involved
20:49 sri $foo->get('/') looks a little better
20:49 simbabque I haven't figured out yet if it's good style to just put methods in the controller that are not actions
20:49 sri but all these are equal $foo->get(''), $foo->get, $foo->get('/')
20:49 simbabque they are? so it eats the trailing slash?
20:49 simbabque or rather ignores it?
20:50 jberger as far as routing is concerned yes
20:50 jberger you can check whether it was there with $c->req->url->path->trailing_slash
20:50 simbabque is there a naming convention for private methods in controllers that are not supposed to be routed to? leading underscore or something?
20:50 jberger leading underscore yes
20:50 jberger those are automagically hidden for you
20:51 jberger you can also hide other methods if you need to, but that's the easiest
20:51 sri it's rare these days that you need it though
20:52 jberger ^^ truth
20:52 simbabque which one is rare?
20:52 sri nobody really uses the :action pleaceholder outside of prototyping
20:52 jberger I rarely even use it then
20:52 simbabque oh there are method attributes? I've not come accross them in the docs yet, but I am skimming only when I get stuck
20:52 jberger ?
20:53 jberger simbabque: no, so the idea is that your routing table is usually static
20:53 purl okay, jberger.
20:53 simbabque sub foo : local { ... }
20:53 jberger argh, wtf purl
20:53 simbabque those things are called attributes iirc
20:53 sri we don't use attributes like that
20:53 jberger who mentioned attributes?
20:53 sri i meant ->get('/:controller/:action')
20:53 jberger ah, I see the confusion
20:53 simbabque sri said ":action" and I blatantly ignored the word placeholder
20:54 sri those are pleaceholders
20:54 sri the only way to route to multiple actions
20:54 simbabque it's late here, sorry
20:54 jberger the idea being that the stash parameter action is used to route to a method
20:54 simbabque but then you're in the same timezone, so it's late there too :)
20:54 jberger so if you have :action in your route you can dynamically route to a method
20:54 simbabque that sounds confusing
20:54 jberger but most of us don't do that
20:55 jberger and that is really the only case where hiding methods from the router should matter
20:56 jberger then again, I still mostly use underscores because it helps me mentally grok which are actions/endpoints and which are auxiliary methods
20:56 jberger (and even though I use relatively infrequently)
20:56 simbabque ok, thank
20:57 jberger np
20:57 simbabque for this whole loading stuff from the db the under approach seems more correct to me, because it avoids calling $c->_load($id) all the time
20:57 simbabque and I assume internally there is also some error handling or something going on
20:58 jberger it will catch exceptions, yes, but mostly you handle those by returning a false value from the under to stop the dispatch chain
20:58 jberger (presumably after rendering something else, like a 400)
20:59 simbabque so should I return $c->reply->not_found; or $c->reply->not_found; return; ?
20:59 preaction the latter
20:59 purl i heard the latter was better
20:59 jberger I can never remember what those return, so I do like the latter
20:59 simbabque ok, thanks
21:00 simbabque does the return value of the last action in the chain matter if it's a good response?
21:00 preaction not really, no
21:00 jberger from the endpoint? no
21:01 simbabque or is it perfectly legal to have a return; as the last statement because the perlcritic rule for subs must have return is there
21:01 jberger gah, never just code because perlcritic tells you to
21:01 * jberger hates that perlcritic causes this crap
21:02 jberger IMO I'd disable that one in a perlcriticrc
21:03 jberger but I don't actually use perlcritic, much like I don't use perltidy (other than here), because getting it them to respect my OCD has proved too hard
21:04 simbabque :D
21:04 simbabque yeah there are some rules that I have fought at work... but some do make sense, but I think you don't need a machine to tell you
21:05 simbabque we've had one that wants /x on every regex with length > 3
21:05 simbabque utter crap, led to m/foo/x -.-
21:09 VVelox joined #mojo
21:12 jberger I like this one, I won this contest in the perlcritic category, even though I don't use it : https://web.archive.org/web/20160330203520/http://dfw.pm.org/winners.html
21:12 jberger OCD FTW
21:15 disputin joined #mojo
21:22 nic What's wrong with "return $c->reply->not_found"?
21:30 punter joined #mojo
21:37 Grinnz nothing really, just might have a misleading implication that the return value of ->reply->not_found is significant
21:37 Grinnz i use it often to shortcircuit out of an action
21:38 Grinnz also, don't do that in an under, since the return value of an under action is actually used
21:40 Pyritic joined #mojo
21:51 VVelox joined #mojo
21:59 simbabque can I give $c->render a formt => 'image/jpeg' with the full mime type?
22:00 Grinnz no, but you can set the content type header manually
22:01 Grinnz or alternatively get the short name using $c->app->types->detect('image/jpeg')
22:01 Grinnz but that can be fragile
22:01 Grinnz gotta make sure you have those types defined
22:01 simbabque I have the mime type, so I'll set the header
22:01 simbabque famous last words: my app only knows about two types and they are defined by default...
22:01 Grinnz $c->res->headers->content_type($foo)
22:04 simbabque thanks Grinnz
22:07 bwf joined #mojo
22:24 Pyritic joined #mojo
22:25 Grinnz damn, bitcoin prices are high atm
22:26 Grinnz wonder why... i havent heard of any improvement in the adoption of it
22:43 sri bitcoins got legalised in japan
22:45 Grinnz interesting
23:23 disputin joined #mojo

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