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

IRC log for #mojo, 2015-07-17

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

All times shown according to UTC.

Time Nick Message
00:19 marty joined #mojo
00:24 AndroUser2 joined #mojo
00:47 * sri yawns
01:01 AndroUser2 joined #mojo
01:14 genio robots don't yawn
01:21 AndroUser2 joined #mojo
01:21 sri lies
01:26 frederico joined #mojo
01:33 jberger -DENABLE_YAWN
01:33 * jberger checked the source
01:34 mattastrophe joined #mojo
02:08 noganex_ joined #mojo
02:46 AndroUser2 joined #mojo
03:10 cpan_mojo Mojo-Webqq-1.3.7 by SJDY https://metacpan.org/release/SJDY/Mojo-Webqq-1.3.7
04:03 thowe So, how do I use url_for to go to /controller/method/arg ?  /controller/method is pretty easy, but how do I add the arg to that?  IN Catalyst I would do like c.uri_for( c.controller('Controller').action_for('method'), (arg) )
04:08 jberger thowe: arg is a placeholder?
04:09 jberger What does your route definition look like?
04:09 thowe it would be /network/branch/:id
04:10 jberger And what is the route name?
04:10 jberger Or is it the default?
04:12 thowe $root->get('/network/branch/:id')->to('network#branch');
04:12 thowe root is under / so I can veryify auth
04:13 jberger Assuming the default, that would be url_for( networkbranchid => id=> $id )
04:13 jberger Or you can make a better route name with the "name" attribute
04:14 thowe er, what?  that's not a typo?
04:14 jberger Nope
04:14 jberger Try it
04:14 thowe wtf?  Where's that documented?
04:15 jberger Default route names?
04:15 thowe http://mojolicio.us/perldoc/Mojolicious/Controller#url_for would not have led me to this
04:16 jberger http://mojolicio.us/perldoc/Mojolicious/Guides/Routing#Named-routes
04:18 zivester joined #mojo
04:19 thowe I don't understand what I'm reading...
04:19 thowe I haven't created this name "networkbranchid"
04:20 jberger You can assign a name with "name" in Mojolicious::Routes::Route, or let the router generate one automatically, which would be equal to the route itself without non-word characters, custom names have a higher precedence though.
04:20 jberger <- quote therein
04:21 Grinnz "jberger"
04:21 thowe *blink*
04:21 * jberger sets Grinnz on fire
04:21 jberger Then puts him out again
04:23 jberger I think I've decided, my mojo book is going to start with named routes as the first topic
04:26 jberger People also don't realize that the lite syntax "get '/' => 'index'" to render the index template is actually seeing the route name
04:26 jberger And the default render template is rendered based on that name
04:26 jberger s/seeing/setting/
04:39 thowe undefined subroutine
04:40 thowe $root->get('/network/branch/:id')->to('network#branch');     <%= uri_for(networkbranchid => id => $root->id ) %>
04:40 thowe Undefined subroutine
04:42 thowe hrm, hang on, I might be able to fix
04:49 thowe yeah, no apparently not..  it doesn't like that name
04:53 thowe networkbranchid totally exists in my routes too....
04:57 sri this section should mention everything you need http://mojolicio.us/perldoc/Mojolicious/Guides/Routing#Named-routes
04:59 thowe I fucked up.  I had uri_for and not url_for....  My fingers thought I was still doing Catalyst....  Also, some other syntax needed fixing
04:59 thowe <%= url_for( 'networkbranchid', id => $root->id ) %>
04:59 sri jberger: that double hashrocket looks silly
05:02 thowe in retrospect, thos eother syntax things prolly would have worked
05:17 kaare joined #mojo
05:22 frederico joined #mojo
05:24 jberger sri: I already linked to that guide
05:25 jberger And yeah my coding style has gone back and forth on the chained fat commas
05:26 jberger thowe: you can give it a nicer name too btw
05:27 jberger Anyway I'm off to bed, nn
05:27 thowe eh, knowing that it shows up when I list the routes helps
05:27 thowe Good night
05:28 sri in that context i would only use two hashrockets like foo => (bar => 'baz')
05:29 sri hmm, mr robot seems to be getting worse :/
05:33 thowe yeah, haven't figured out those characters yet.  First episode was OK
05:33 thowe first scene
05:33 purl first scene is probably awesometastic
05:34 sri i liked the first three episodes, but in this one it seems like they don't know where to go with the story
05:36 thowe larger story...  everything can't be awesome
05:37 thowe They've done moral ambiguity pretty well
05:37 thowe I mean, I would have done something mean to slater after that push off the bridge.  the fuck was that?  That guys odd
05:39 sri he's imaginary
05:39 thowe yeah, I thought that too, but then how did he get to the "clubhouse"?
05:40 thowe or are all of them imaginary?
05:41 thowe No, the drug dealer saw the one gal
05:41 thowe Now I have to go back and watch again....
05:41 thowe crap
06:05 jontaylor joined #mojo
06:05 jontaylor 7AM is too early :( eugh
06:06 dvinciguerra joined #mojo
06:17 ans joined #mojo
06:28 absolut_todd joined #mojo
06:30 jzawodn joined #mojo
06:39 dexteruk_ joined #mojo
06:43 dod joined #mojo
06:48 dod joined #mojo
07:10 AndrewIsh joined #mojo
07:13 berov joined #mojo
07:14 trone joined #mojo
07:21 eseyman joined #mojo
07:39 ans1 joined #mojo
08:06 hshong joined #mojo
08:28 Vandal joined #mojo
08:52 teejay joined #mojo
09:03 punter joined #mojo
09:03 McA2 joined #mojo
09:17 irqq joined #mojo
09:46 marty_ joined #mojo
09:50 ashimema hi guys
09:50 ashimema got a rever proxy issue.. running morbo on localhost and using apache to reverse proxy infront of it.
09:51 ashimema inside one of my controller I use req->base to get the base url.. the url is correct as per the outside dns entry.. but the protocol is always http,
09:52 ashimema do I need to run morbo on https for that req->base to ever get https?
09:52 ashimema the reverse proxy is https
09:52 Lee_ joined #mojo
09:55 shadowpaste "ashimema" at 217.168.150.38 pasted "proxy settings" (28 lines) at http://paste.scsys.co.uk/493433
09:56 ashimema anything obviosly wrong there?
09:56 ashimema pretty please
10:00 CandyAngel Sorry, I haven't started using reverse proxies or anything yet
10:01 CandyAngel I would imagine that you have to set the proxy to consider the backend (morbo) as a https thing
10:02 CandyAngel Maybe it "strips" the https because the https is between the browser and the httpd (proxy)?
10:02 CandyAngel Sorry, wild guessing really
10:03 ashimema hmm
10:03 ashimema need to do some digging me thinks
10:04 marty joined #mojo
10:05 CandyAngel I guess it depends if the http stream gets decrypted at httpd or passed through to the proxy
10:27 batman ashimema: have you looked in the cookbook?
10:29 ashimema I have indeed..
10:29 ashimema sorted it now..
10:30 ashimema needed to enable SSLProxyPass and then stick the background mrobo on HTTPS too
10:30 ashimema or at least that was one way round to do it ;)
10:34 CandyAngel ashimema: Yay, you got it sorted :)
10:36 neilhwatson joined #mojo
10:53 till joined #mojo
10:59 till it would be nice if you could pass a route name to $t->get_ok()
11:31 dotandimet joined #mojo
11:46 batman till: i disagree. that would not test that the url is correct.
11:58 till maybe with preceding slash = url; without = route ?
11:58 till get_ok('/url'), get_ok('route')
11:59 nicomen you can easily do a route_ok() method that looks up
12:00 nicomen GET some-url HTTP/1.1
12:00 nicomen is valid
12:09 frederico joined #mojo
12:10 nicomen https://gist.github.com/nicomen/f0b3201986e1b26df792
12:11 nicomen till: ^
12:15 punter joined #mojo
12:15 mattastrophe joined #mojo
12:16 till thanks, looks good. so far I always did $t->get_ok($t->app->url_for('route'))
12:17 nicomen ah right, that's proabbyl simpler
12:18 nicomen but merging it into get_ok imho is problematic due to the params you might want to use
12:19 till $t->app->url_for('route', {id => 1}) does work
12:20 till but it would be nice if I could do it without url_for :)
12:27 Andreas joined #mojo
12:35 ajr_ joined #mojo
12:44 PryMar56 joined #mojo
12:55 jberger I agree with batman, you are testing your paths too
13:10 punter joined #mojo
13:16 zivester joined #mojo
13:22 Flying_Squirrel joined #mojo
13:58 dotandimet joined #mojo
14:19 dvinciguerra joined #mojo
14:25 bc547 joined #mojo
15:12 neilhwatson For one controller to use another controller's helper, do you need to pass the helper or is there some mojolicious way?
15:13 jberger helpers are not bound to a controller
15:13 jberger it will get the current (the invoking) controller
15:14 mst helpers are app-global
15:14 jberger unless you invoke them on the app I suppose
15:14 neilhwatson How do you access them then?
15:14 mst since they're attached to the renderer
15:14 mst in a controller, $self->helper_name(...) will do the right thing
15:14 mst there's an AUTOLOAD that proxies it
15:15 neilhwatson I'm doing something wrong. I get a renderer error.
15:16 mst http://paste.scsys.co.uk/mojo # show us stuff
15:16 neilhwatson yep
15:22 shadowpaste "neilhwatson" at 217.168.150.38 pasted "using helpers in another controller" (52 lines) at http://paste.scsys.co.uk/493484
15:23 mst um
15:24 neilhwatson Is it bad?
15:24 mst that code makes no sense at all
15:24 mst you're attempting to instantiate a controller object by yourself in a helper
15:24 mst not even passing it an application object
15:24 mst then calling a feature that uses the application object
15:24 mst this is ... not logical
15:26 mst I think the real question is - why is hostcount() a method on a specific controller? if it's required multiple places, surely it's a model method?
15:27 mst it's the 'dash' helper that doesn't make any sense, anyway
15:28 neilhwatson You're right, Dashboard is not a controller, I don't think. It's just a place to stash some subs related to a dashboard.
15:29 mst right, so don't treat it as a controller, instead pass it $app->dq when you construct it, or pass it $app and let it call ->dq on that
15:29 neilhwatson ok will try that.
15:30 mst though I wonder if a helper even makes sense for that - if the object can persist across requests ok, why not just use 'has' ?
15:32 neilhwatson has?
15:32 purl rumour has it has is done with suffering fools gladly this day
15:33 mst um, to declare it as an attribute?
15:33 mst just like you do in any perl5 OO from the last decade?
15:33 irqq_ joined #mojo
15:33 mst Moose/Moo/Mojo::Base all provide 'has'
15:33 mst (although Mojo's has fewer features)
15:33 jberger does that purl factoid make any sense to anyone?
15:34 * jberger considers nuking but doesn't want to remove something funny he just doesn't get
15:36 Grinnz_ purl: forget has
15:36 purl Grinnz_: I forgot has
15:36 Grinnz_ it doesn't make grammatical or logical sense, no :P
15:38 mst purl, has is <reply>
15:38 purl OK, mst.
15:40 neilhwatson thanks for the tips.
15:51 sh4 joined #mojo
15:54 sri how annoying, some guy keeps spamming me on twitter with ignorant statements about our docs :S
15:54 mst sri: twitter now provides both mute *and* block
15:54 mst pick whichever makes you happiest :D
16:01 jberger I really don't understand people's ... miscomprehension ... of our docs
16:01 jberger we could just have no docs at all!
16:02 jberger ever tried to do mason via just the docs?! damn near impossible, you need the mason book to do any sufficiently advanced stuff
16:02 dotandimet1 joined #mojo
16:03 gryphon joined #mojo
16:10 disputin joined #mojo
16:30 stephen joined #mojo
16:39 dod joined #mojo
16:42 CandyAngel There is something about the Mojolicious docs, but I can't explain it
16:42 jberger they are dense, and people want to skim
16:42 jberger that's the true failing as I see it
16:43 jberger every sentence is crafted to contain as much information as possible, and people aren't used to that level of detail being important
16:43 CandyAngel True
16:43 jberger I often tell a new user to read the entire Guides, then read them again
16:44 CandyAngel Maybe because they are so dense, they lack the variety of key words that people look for
16:44 jberger not because they aren't in the right order, but that they can't have possibly soaked it all in in the time they gave it on the first round
16:44 jberger CandyAngel: that's not really our fault though
16:44 CandyAngel I know, not saying it it :P
16:44 CandyAngel it is*
16:44 jberger k
16:47 CandyAngel Next time I am looking at the docs, I'll see if I can pick an example of what is "off" about them
16:47 CandyAngel But as I said, i can't explain it
16:47 meredith some things are p subtle in the docs compared to many projects, like the name chosen to hold invocants is telling the reader something important, and most leave an ambiguous $self
16:47 jberger CandyAngel: everyone says that, they rarely can actually find an example of what they don't like
16:48 CandyAngel Eh, I know there are specific examples :P
16:48 trone joined #mojo
16:48 CandyAngel like umm.. Mojo::DOM. I read the examples and I'm like.. what, I know it just told me what X does, but I still have no idea
16:49 jberger Mojo::DOM is a little different than most in that it doesn't really appear in the Guides
16:49 sri patches welcome
16:49 purl patches welcome is, like, always true or even for metacpan.org or swahili for "Put up or shut up."
16:49 CandyAngel sri: Of course :)
16:49 meredith (tangent here: i'm drudging through subroutine attribute routing hell in Catalyst today; i miss you mojolicious)
16:49 CandyAngel Which reminds me, I don't think I've had any feedback on my Thunar patch :(
16:49 Grinnz_ i see the problem with the mojo docs (for new people) is that they're written very methodically, people are used to docs which kind of sprawl and point you everywhere, but Mojo covers so many things that doing that would be unmanageable
16:50 jberger for the most part module level documentation is just supposed to be a reference, but with a few of the "batteries included" classes it is the only documentation
16:50 * jberger considers a Mojolicious::Guides::BatteriesIncluded for ::DOM and ::JSON
16:50 sri Grinnz_: our docs are not very different from the docs of other web frameworks
16:50 CandyAngel Grinnz_: that's what I meant about keywords. The more you write, the more likely you will happen to use a keyword the reader is skimming for
16:50 Grinnz_ sri: the well written ones, yeah
16:52 sri the terminology in Mojo::DOM has been very very carefully chosen btw.
16:53 CandyAngel I get the feeling that everything in Mojolicious was carefully chosen :P
16:53 Grinnz_ jberger: i'm not following what you mean by batteries included
16:53 CandyAngel See: on hold jobs :D
16:53 sri in fact, i consider the Mojo::DOM redesign from 6.0 a huge success
16:54 Grinnz_ i agree
16:54 jberger sri: yes it has been chosen carefully, I'm just thinking of how we usually say that the module level documentation is only for reference and not education
16:54 sri we've had like almost no problems since
16:54 jberger that's not entirely true of the DOM and JSON
16:54 jberger oh, I absolutely agree, the new ::DOM api is a huge success
16:54 jberger definitely worth the breakage IMO
16:55 jberger CandyAngel: yes, the more you are around the more you see the care we like to put into everything, or at least I hope you do
16:55 jberger which is part of what attracted me to the project in the first place
16:55 sri DOM and JSON are still very much reference docs imo
16:55 sri same for Template
16:56 berov left #mojo
16:56 sri the docs explain exact semantics on a very small context
16:56 CandyAngel For example,a very minor thing is in Mojo::DOM, you have the result of the example, *then* the example code..
16:56 jberger at least Template gets an appearance in the Rendering Guide
16:56 Grinnz_ yeah
16:56 sri CandyAngel: how would you write it?
16:56 Grinnz_ a DOM and JSON guide might be nice
16:57 Grinnz_ dealing with traversing external APIs, or creating requests, or creating XML
16:57 sri Grinnz_: guides start at 700 lines, i don't think you can write that much about the two
16:57 Grinnz_ oh there's a minimum :D
16:57 jberger sri: about the two together I'm sure you could
16:57 Grinnz_ it would be a stretch but i think it's doable
16:57 CandyAngel sri: the other way around? Perhaps even: original, code, result
16:58 sri CandyAngel: example?
16:58 purl Example (noun): A thing characteristic of its kind or illustrating a general rule.
16:58 sri CandyAngel: and be aware that you're proposing a project wide convention
16:58 CandyAngel http://codepad.org/gKuusF3r
16:59 CandyAngel it's a lot clearer to me what the code actually does like that
16:59 CandyAngel But how it is, it says what it will be, then "run" the code with the original text in the code
17:00 sri there's 273 results for '# "', many of those are similar cases
17:00 CandyAngel It'd be even better if the modifed bit was emphasised
17:01 CandyAngel sri: if you agree it is better, I can send a patch to change them
17:01 sri in many cases there's no before
17:02 sri i'm meaning to say that consistency will be almost impossible with your proposal
17:02 till is the uninitialized warning intended when build a DOM from an empty string? perl -Mojo -E "say x('')->text"
17:03 sri CandyAngel: or this one http://mojolicio.us/perldoc/Mojolicious/Controller#url_for
17:03 jberger I'm not sure there needs to be a before, but when it is clearly a result of a code line, the result (in the comment) could be following code
17:03 Grinnz_ till: probably along the lines of "doing this wouldn't make much sense"
17:03 CandyAngel sri: if the method isn't mutating something, you'd just omit the original?
17:03 sri how would you put the result consistently after the code?
17:04 sri CandyAngel: i'm asking you! ;p
17:04 Grinnz_ result after the code seems like a good idea to me as well
17:04 Grinnz_ i've often been a bit confused by that in examples
17:04 sri Grinnz_: make a real proposal
17:04 CandyAngel How odd, I'm like.. Mojo is the only documentation I can think of that has the example first, now I am mindblanking on any modules that have any examples in their docs >.<
17:05 jberger Grinnz_ hasn't made a core contributor proposal yet, get on it! :-P
17:05 jberger CandyAngel: I think the reason it got this way is the comment usually come before code in regular course of coding
17:06 jberger and in many cases the comments aren't truly results
17:06 CandyAngel Yeah, that makes sense
17:06 Grinnz_ i think they are trying to be "headings", which makes it confusing when they are the result of their "section"
17:06 jberger but where they ARE truly results, following makes sense
17:06 till Grinnz_: it can happen if $ua->get returns an empty response and you call $tx->res->dom->all_text on it
17:07 jberger I suggest re-reading http://mojolicio.us/perldoc/Mojolicious/Guides/Rendering and seeing what comments are more like the conditions/environment vs results of some operation
17:07 CandyAngel Like.. if you are reading that, you read the result, then read the code, then have to look back up to see what it did
17:08 sri it's the *expected* result
17:08 CandyAngel Rather than read the code (which tells you the original, and the change), then the "result comment" so you can see where it put the change in the original
17:08 sri not the actual result, we're not using a REPL
17:09 sri or to be more precise, a comment with the expected result in quotes
17:09 CandyAngel Mhm, I understand
17:10 sri it's not at all meant to look like code you've thrown at a REPL
17:10 sri if you want that style, things get odd because most perl people are not even familar with one
17:11 sri since, unlike ruby, perl doesn't really ship with one
17:11 Grinnz_ it's not about REPL, it's about cause -> effect
17:11 sri that sounds a bit ignorant
17:11 CandyAngel Okay, really lame example http://search.cpan.org/~rjbs/Time-Piece-1.30/Piece.pm#Date_Parsing
17:11 sri the point is that people can relate to the example
17:12 till maybe you could change line 190 in Mojo::DOM to something like ($_->[1] // '') eq 'pre' ...
17:12 sri anyway, please make a real proposal
17:12 * sri is out
17:13 Grinnz_ it would be very time consuming, so i'll do it in a couple days if nobody else has
17:15 sri famous last words
17:15 purl please hold while I connect you.
17:15 Grinnz_ lol purl
17:22 sri till: maybe
17:28 berov1 joined #mojo
17:28 dod joined #mojo
17:29 jontaylor potentially stupid request : How about encode_json and decode_json as default helpers.
17:29 jontaylor i say potentially stupid because my spidey sense tells me I might be doing something in a stupid way
17:29 sri use case?
17:30 Grinnz_ jontaylor: you could make them helpers easily enough i guess..
17:30 jontaylor say you have some fancy js widget, such as a chart in your template, and you generated the data server side, and you want to pass that into the template, you pass your perl hash in, and then you need to specify that data in your javascript
17:30 disputin joined #mojo
17:30 jontaylor normally i’d make it a webservice and do another trip from the client back to the server
17:31 Grinnz_ oh god, the passing JSON into a template thing again
17:31 sri jontaylor: yes, that's very stupid, because encode_json gives you double encoded data
17:31 jontaylor Grinnz_:  it does feel a bit icky
17:31 sri it's just plain wrong
17:32 jontaylor I can accept that, but what is the prefered convention?
17:32 Grinnz_ have the javascript get data via a real API
17:33 Grinnz_ then use parseJSON or whatever on it
17:33 jontaylor but what if the exact same query was just done for something else thats already in the template
17:33 Grinnz_ i don't follow
17:34 mst what he means is
17:34 purl he means is $name is "/etc/passwd".
17:34 jontaylor you do a query to get some data, pass it into your template to generate say a HTML table, but you then have a JS chart displayed based on that data
17:34 mst "I already needed that data to render it into a table"
17:34 mst "therefore it seems stupid to fetch it twice"
17:34 mst which it is
17:34 neilhwatson joined #mojo
17:35 mst I'm not honestly sure why mojo people seem to think 'make the same request twice' or 'so rewrite your perl into javascript instead' are good answers here
17:35 mst because, frankly, while what jontaylor is doing is pretty janky
17:35 mst the alternatives you're giving him are even stupider
17:35 Grinnz_ because then you aren't injecting JSON into a template
17:35 jontaylor it does feel really janky, so I am really open to alternatives
17:35 mst Grinnz_: and?
17:35 sri mst: i never said that
17:36 mst I fail to see how "double the load on your backend" is better
17:36 sri Grinnz is not all mojo people
17:36 mst sri: you said what he's doing was wrong. you've yet to suggest a better answer.
17:36 mst also I've seen this conversation happen repeatedlty
17:36 sri i don't have to fricking do anything
17:36 mst Grinnz is not all mojo people, but he's far from the first person in here to say the same thing
17:37 mst so, so far, that's what I've seen mojo people suggest
17:37 mst and you're right, you don't. but if you don't make a better suggestion, my statement that mojo people generally don't make a better suggestion will continue to be true
17:37 sri i'm not going to reward this bullshit with an answer
17:37 * sri leaves
17:38 mst *flounce*
17:38 jontaylor I don’t think anyone is obliged to give me a better solution btw
17:38 mst Grinnz: so, got any actual suggestions?
17:38 mst no, but I think there -should- be a better solution
17:38 mst and I'd rather try and find one rather than just tell you you're wrong then refuse to help
17:38 jontaylor this       var charts = <%== Mojo::JSON::encode_json($charts)  %>; is clearly wrong
17:39 mst although, surely, if you turned it into a bytestream, it would work?
17:39 jontaylor i could tell when I was typing it out, but going back to the server again to process through 32 million records for a second time also seems suboptimal
17:40 mst what happens if you do <%== Mojo::ByteStream->new(Mojo::JSON::encode_json($charts)) %> ?
17:40 jontaylor testing
17:40 mst I somehow doubt that's the right answer, but it might at least avoid double encoding
17:41 jontaylor mst: everything continues to work
17:42 mst jontaylor: I'm pretty sure it only accidentally worked before
17:42 mst then again, it probably only accidentally works now
17:42 mst and I've just moved you from one bug to another ;)
17:42 jontaylor thats what i’m worried about
17:42 jontaylor i’m ok right now in that none of this is user supplied
17:42 jontaylor but i’ll eventually stick something in there that came from an external source
17:42 mst right
17:43 good_news_everyon joined #mojo
17:43 good_news_everyon [mojo] kraih pushed 1 new commit to master: http://git.io/vm6JS
17:43 good_news_everyon mojo/master 5a399f7 Sebastian Riedel: fix warnings in Mojo::DOM
17:43 good_news_everyon left #mojo
17:43 sri till: that should do it
17:44 trone_ joined #mojo
17:45 sri jontaylor: http://mojolicio.us/perldoc/Mojo/JSON#to_json
17:46 * sri just doesn't want to deal with any more jerks like mst today
17:46 meredith I def don't like using JSON to write in JS obj literals. if the containing page is definitely rolling out in UTF-8, can you `var foo = JSON.parse('<%== Mojo::JSON::to_json($foo) %>');`?
17:46 meredith i haven't noodled on the encoding/quoting issues deeply on that though
17:46 jontaylor i’m going to give that a try now
17:47 jontaylor I imagine i can test this better if I change my test data to have an assortment of quote characters and line feeds etc
17:50 meredith be sure to include character codes >128 in those tests to see if it's coming through clean and/or acceptable casualties :P
17:51 jontaylor ♥ should do it
17:52 sri meredith: only u2028, u2029 and "/" should be problematic, and Mojo::JSON takes care of those already
17:52 punter joined #mojo
17:54 jontaylor my test string of "\" ' ''' / // \/ /\  \\\\  \n\n  \r \t  ♥ ♥♥♥ ' " seems to come through without harm
17:54 meredith well, ♥ is all you need.
17:54 jberger eeeep, I'm sorry I was getting lunch, to_json is not utf8 encoded, which is what you want
17:54 jberger since the template will be utf8 encoded later
17:55 jontaylor jberger: do you also consider what i’m doing bad practise though?
17:55 jberger jontaylor: as mst said, its not great, but in some cases its the be ya got
17:57 mst it's a bit ugly, but I can't see an alternative that isn't worse
17:57 mst except for 'render the table client-side as well'
17:57 Grinnz injecting JSON into a javascript section of an HTML document is sufficiently poisonous that while with the workarounds that have been added to Mojo::JSON they should work (unless you are using Mojo::JSON::MaybeXS, in which case they won't), i prefer getting all data from javascript to begin with
17:57 mst at which point you have two HTTP requests but only one request to the backend
17:57 Grinnz of course that is a redesign and not a solution, which is why i can't really suggest it generally
17:57 mst since the template doesn't have to call the backend
17:57 mst but ... that's not always the right answer
17:57 Grinnz right
17:57 Grinnz that's the answer i would -always- pick myself though
17:58 jontaylor Grinnz: It isn’t out of the question if its a significantly big faux pas
17:58 sri if we had http/2 there would be a third solution too
17:59 sri server push the json to the browser together with the original html document, then it is already in the browser cache
17:59 jontaylor I guess since we don’t have http/2 yet another option could be to jam the data into memcache or equivalent, then do the second request, and pull it out like that
17:59 Grinnz sri, damn, that sounds nice
17:59 mst well, I think jberger's right, and to_json should be ok
18:00 Grinnz to_json should work if you are not and don't plan to ever use a JSON encoder other than Mojo::JSON
18:00 mst Grinnz: JSON::MaybeXS provides a to_json though
18:00 Grinnz a to_json that does not escape the problematic characters
18:01 Grinnz which i think is a hack in the first place, but it's what allows that to work
18:01 sri funny how i predicted this situation
18:02 sri when automatic escaping of "/" was proposed for security
18:02 mst Grinnz: ah, I see
18:02 sri i warned that it could lead to security issues with JSON::MaybeXS ;p
18:02 jberger I see it as just another thing that Grinnz can add to the "differences" section
18:02 Grinnz it's already there
18:02 jberger tada!
18:02 Grinnz https://metacpan.org/pod/Mojo::JSON::MaybeXS#Escapes
18:02 jontaylor sri: doing this isn’t that stupid of a use case though is it, especially if the content was expensive to generate
18:04 sri jontaylor: depends i guess, if your data changes frequently you're sacrificing cacheability
18:04 sri with a second request for json you'd keep the html cacheable
18:04 jontaylor sri: thats a good point, the data changes by the second in this case
18:05 sri then second request wins clearly
18:05 jontaylor but the HTML is trivial in comparison to the DB query, and its easier to add more app servers than DB servers
18:06 mst right, but the idea is you make the query -only- for the json request
18:06 jontaylor oh right, and then use some javascript templating to generate the rest of the page?
18:06 mst and the html+javascript renders both the chart and table
18:06 CandyAngel Um
18:06 mst and then the entire hairball goes away
18:07 CandyAngel I know this might be stupid because I'm not 100% sure what you are talking about.. but could you fetch the data (to put into the template), but also write it out to a UUID-named file and pass the UUID to the template too. Then have the second request just request the cached file (i.e. static file)
18:08 Grinnz yeah that's a bit stupid :P
18:08 CandyAngel So template and second request always get the same data, but the second doesn't incur the generation expense?
18:08 Grinnz javascript has templating engines, they work
18:08 mst that's another variant on "cache the data"
18:08 meredith then you have to clean up that file cache as well.
18:09 sri but, cache invalidation was easy, right?
18:09 mst jontaylor: you're already generating the chart with JS, generating the table the same way basically makes the problem go away
18:09 Grinnz lol
18:09 mst sri: are you sure that's the right name for it?
18:10 CandyAngel You could have the second request delete the file, if you always know it will only be those 2 requests
18:10 CandyAngel Just throwing it out there in case my weird way of looking at things had some merit (sometimes it does, honest :P)
18:10 jontaylor oh crap, i’m 10 mins late picking the gf up from work!
18:10 meredith agreed about JS templating, as long as you're fine not having the table in the page-as-sent
18:10 mst yeah, but then if the second request never arrives you still need cleanup
18:10 jontaylor I’ll be back ina  bit guys, and catch anything missing on the irclog
18:10 jberger CandyAngel: I would rather have a CHI instance that caches the data
18:10 meredith that's more important, get goin'
18:10 jontaylor thanks for all the help everyone
18:11 CandyAngel jberger: Yeah, or that
18:11 till sri: thanks :)
18:11 jberger CHI's compute is so handy
18:11 jberger https://metacpan.org/pod/CHI#compute-key-options-code
18:11 CandyAngel and you could schedule a minion job to delete the file after some time (or invalidate the CHI cache or whatever)
18:11 jberger CHI does the invalidation for you
18:12 jberger by time
18:12 jberger or condition
18:12 purl i heard condition was always a hashref
18:12 CandyAngel Hm.. I thought it invalidated it, but didn't delete it
18:12 jberger purl forget condition
18:12 purl jberger: I forgot condition
18:13 jberger CandyAngel: define delete?
18:13 CandyAngel Deleting the file off the disk
18:13 CandyAngel Um
18:13 jberger if the cache isn't used anymore, thus invalidated, then who cares?
18:13 CandyAngel if you are using the file backend :P
18:13 jberger sure, if you are using the file backend, but I would expect that backend to be able to cleanup after itself
18:13 * jberger uses FastMMap anyway
18:14 CandyAngel Hm
18:14 CandyAngel I should just start asking people what modules they use
18:14 CandyAngel Like.. Devel::Dwarn <3
18:14 jberger https://metacpan.org/pod/CHI::Driver::FastMmap
18:14 jberger ^^ good for a single server using hypnotoad
18:15 CandyAngel Ohh.. it's a CHI backend
18:15 CandyAngel Coolies
18:15 jberger for multiple hypnotoad servers (if its worth sharing caching across boxes) you would need some kind of external keystore
18:15 * CandyAngel has a looksee
18:15 mst just member that Cache::FastMmap is hilarious and generally disrecommended
18:15 mst because if your cache entry exceeds the page size it silently drops it
18:16 jberger mst: :s
18:16 mst so at some point as your data set gets largely your cache magically breaks
18:16 mst which is hilarious when it happens on production first
18:16 jberger well, poop
18:16 jberger ????
18:17 jberger well has someone written a backend using File::Map yet?
18:17 jberger it would need some structure too
18:17 mst Cache::FileCache isn't a bad choice for a single server
18:20 jberger too bad there is no CHI driver for it
18:21 mst uh, it follows the Cache::Cache API
18:21 mst why would it need a special driver?
18:22 mst https://metacpan.org/pod/CHI::Driver::CacheCache
18:22 mst the synopsis tells you how to use Cache::FileCache
18:22 jberger ah, mst++
18:32 _dave_ ack
18:35 Dave I did -not- know that about Cache::FastMmap
18:37 Dave maybe I missed something, but that's the only one (without installing memcached) that could do a get_and_set semantic
18:37 jberger Dave: that's just the compute method
18:37 jberger of CHI
18:37 mst https://metacpan.org/pod/Cache::FastMmap#PAGE-SIZE-AND-KEY-VALUE-LIMITS
18:38 mst in their defence, they do absolutely document it
18:38 Dave that explains why my production module hasn't failed
18:38 Dave I check the return value of set
18:38 jberger I would hope that the CHI driver does too
18:39 Dave so I just spent some hours writing an adapter for a shared cache among preforked mojo processes
18:39 mst yeah, but your question then is "if it fails, what do you do other than have no cache?"
18:39 Dave you have no cache *wince*
18:39 mst so, at least you're logging that you have no cache
18:39 Dave I have a workaround, I write it to a file if set fails...apparently I set the page size very large
18:39 jberger https://metacpan.org/source/JSWARTZ/CHI-0.60/lib/CHI/Driver/FastMmap.pm#L65
18:39 jontaylor joined #mojo
18:39 Dave because I've never written those files
18:40 Dave but when I was writing this adapter, FastMmap and the DBI chi driver were the only two that offered real key locking
18:40 Dave unless I'm missing something
18:40 mst ah, awesome, so it'll blow away the request entirely, while attempting to recompute it every time a new request comes for that data
18:40 Dave lol
18:41 Dave I'm not using it as a cache in production yet, my production module caches database results
18:41 Dave "caches"
18:41 jberger mst: now that you put it that wa
18:41 jberger way
18:41 Dave so the worst is another database look up
18:41 mst at least the logs will make the problem obvious
18:41 Dave yes
18:41 mst rather than silent failure, which is what I've seen previously
18:41 Dave I log too much :/
18:41 mst but I'm still not amazingly fond of it anyway
18:41 Dave so what do you use? :D
18:43 Dave I didn't use CHI fastmmap because CHI's "atomic operations" are a) in alpha and b) don't really work except for libmemcached and dbi
18:43 Dave according to the docs
18:43 Dave I like the idea of CHI tho
18:43 mst still not sure what's wrong with Cache::FileCache via CHI
18:43 mst what 'atomic operation' do you actually want?
18:43 Dave locking a single cache key
18:44 Dave what might be confusing is I'm not using this as a strict cache, I'm storing data I want shared between preforked servers
18:44 amon joined #mojo
18:44 Dave e.g session data, auth data
18:45 Dave mst: look at the add() and replace() semantics in CHI under atomic operations...if those worked they would be fine
18:45 mst right, I've always written that such that it didn't matter ... or used something other than a cache
18:46 mattastrophe joined #mojo
19:16 Kogurr joined #mojo
19:20 mattastrophe joined #mojo
20:07 bin_005 joined #mojo
20:13 xdg left #mojo
20:35 punter joined #mojo
20:54 ajr_ joined #mojo
20:56 disputin joined #mojo
21:11 bin_005 joined #mojo
21:48 disputin joined #mojo
22:24 disputin joined #mojo
23:22 frederico joined #mojo
23:56 ajr_ joined #mojo

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