Camelia, the Perl 6 bug

IRC log for #mojo, 2013-01-14

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

All times shown according to UTC.

Time Nick Message
00:02 yakubori joined #mojo
00:11 Molaf_ joined #mojo
00:12 berov left #mojo
00:21 dhg left #mojo
00:34 Averna joined #mojo
00:34 ka2u joined #mojo
00:41 jberger ALL GLORY TO THE HYPNOTOAD!!!
00:56 PanzerBjorn joined #mojo
00:57 PanzerBjorn Is there anything special you need to do for Mojo to process AJAX requests? I'm getting a 500 error on an AJAX request that works fine when I use the URL normally in a browser Location bar.
01:02 xaka joined #mojo
01:08 marty PanzerBjorn:  afaik, Mojo should respond the same.
01:09 sri how do you even differentiate between browser and ajax requests?
01:11 PanzerBjorn By checking the XHttpRequest header, but in this case I'm not even doing that.
01:11 sri that only works for frameworks like jquery, not vanilla ajax
01:11 Mike-PerlRecruiter_ joined #mojo
01:11 PanzerBjorn Well, I'm using jQuery.
01:11 sri and you mean X-Requested-With
01:12 PanzerBjorn Something like that, yeah. Like I said, I'm not even doing that.
01:12 PanzerBjorn (Yet)
01:12 sri my point being, your question makes no sense
01:12 marty which can be checked with $c->req->is_xhr  --  I loves Mojolicous.  Makes things easy.   \o/
01:12 PanzerBjorn Well, why does Mojo throw out a 500 when jQuery's .get() calls a URL that 200's every time for me from the Location bar?
01:13 PanzerBjorn (And there's not even anything being logged in the develeopment.log file)
01:14 PanzerBjorn I just assumed that Mojo was detecting that jQuery was making a call, and it was spazzing, I assumed I didn't tell Mojo it can take jQuery request or somesuch like that.
01:15 marty It should respond just the same.  Sounds like you have a mangled url in your get command or perhaps using a different HTTP method
01:15 marty prolly a mangled url if nothing is hitting the logs
01:16 PanzerBjorn Firebug's reporting the URL as correct. =/ The headers all look good too. I'll keep poking around.
01:16 marty correct port?
01:17 PanzerBjorn Port's masked by reverse proxy, this is going through an Apache server to Morbo.
01:17 sri dammit... i hate it when i'm working on an optimization and it turns out slower than the original :S
01:17 sri obviously your apache is throwing the 500
01:18 marty hehe:  sri: then that shows how good the original is.  Celebrate!!!!!
01:18 marty ~o~
01:19 PanzerBjorn Curious how Apache would be throwing the 500 when Mojo processes static files requested by jQuery AJAX just fine.
01:19 sri but i don't understand why it is faster :/
01:21 marty Rumor has it only Cylons obsess about optimizing code in the early morning hours.   hmmmmmm
01:21 sri so... it seems substr chopping off snippets from the start of some binary data is cheaper than moving around that binary data with substr and an increasing offset
01:21 marty Tempire was right - sri is a robot!
01:23 marty Perhaps chomp|chop have to walk the entire string?   Dunno, wild guess
01:23 sri it's a length prefixed binary protocol
01:23 marty Ohhh, guess not then.
01:24 sri i have no clue how perl strings actually look internally though
01:25 sri perhaps chopping off stuff from the start is cheap
01:35 sri http://pastie.org/5680890 # i don't quite understand this
01:37 sri oops
01:39 sri http://pastie.org/5680904
01:40 sri i even messed up in the first benchmark and modifying a string is so dirt cheap it doesn't make a difference
01:40 PanzerBjorn How do you change which layout you're going to have used prior to calling a $self->render()? For instance, I tried a "if ($self->req->is_xhr) { $self->stash( layout => 'ajax' ); }" but all I got was a warning in the log about layout being reserved... Is there a different accessor for layout?
01:42 marty sri:  from your pastie, on my system Modify wins by almost 4 seconds
01:43 sri yea, it seems to always win and i wonder why
01:45 marty PanzerBjorn:  you have to wrap it in a before_dispatch hook.....  https://gist.github.com/4527228
01:45 sri oh, perhaps it's a linked list internally, then chopping off from the start would be one of the cheapest operations, while searching the middle takes time
01:46 PanzerBjorn You can't just use the DefaultHelper $c->layout(<name>) format?
01:46 marty I think the most elegant way to do it would be a helper but I have not had a chance to look at it for a while since the hook works ok for me.
01:47 PanzerBjorn Ah, and the hook works site-wide, correct?
01:47 * marty nods
01:47 sri marty: there's a layout helper :)
01:48 sri also title and extends
01:48 PanzerBjorn If I get a non-XHR request to this route, though, I want to do a redirect_to instead of a render, though.
01:51 buu How do you determine if a request is XHJR?
01:51 * buu wonders about the j
01:51 * marty wonders the same thing
01:52 PanzerBjorn $c->req->is_xhr
01:52 PanzerBjorn Thanks to Marty for pointing that out to me.
01:54 buu Does it look at a header?
01:54 PanzerBjorn I believe so.
01:54 * tempire used to dislike sql until he started using mongodb
01:54 buu haha
01:55 marty tempire:  Really?  I kinda like the mongodb query syntax.
01:55 marty I'll admit that it's very limited in some respects to sql, but in some ways I really like it.
01:55 tempire It's a hodge-podge of, oh, we need to be able to do this, let's add another $
01:56 marty ya, those $ commands do kinda suck.
01:56 buu It's not as clean as sql for somethings but it has advantages of being simple
01:56 tempire it's like the java of query languages
01:56 tempire no consistent theory of implementation, just add a structure
01:57 tempire I'm also just frustrated.
01:59 tempire FRUSTRATED!!!
01:59 marty tempire; Just '$push' '$all' those frustrations '$in' another direction that is '$lte" your current state of mind.  :)
02:00 marty step back everyone, he's gunna pop!
02:00 marty :)
02:00 tempire '$elemMatch' => 'rage'
02:00 * sri hugs mongodb
02:02 marty Ahhh, I agree.  the $ElemMatch and projections gave me some issues the other day.   I cant remember exactly what it was but something about pulling info out of an array object.
02:03 tempire I'm trying to figure out how to upsert a hashref into an array position.
02:04 tempire $set is just overwriting what's already there.
02:16 marty tempire:  Can you use $push.     id:   db.collection.update({ 'id' : 123 },{$push: { mypath : {'a':1, 'b':2}   } } );
02:17 marty s/id/id:/
02:17 marty ie!!!!
02:17 marty wow, I cannot type
02:19 PanzerBjorn If I want to select the sub in a controller based on a placeholder, how do I send that in the ->to() postion? I.e. in the follow route, what replaces the question mark?   $b->route('/comments/:action/:id.html', action => [qw(view post refresh screen lock hide)], id => qr/\d+/i)->via(qw(GET POST))->to( controller => 'comments', action => ? )->name('commentsaction');
02:19 PanzerBjorn s/postion/portion/
02:21 * marty is afk - going to watch some bsg
02:33 duncanthrax joined #mojo
02:33 tempire huh.  so you cannot add fields to a sub array, apparently.
02:33 tempire you can only replace the sub-array position.
02:33 tempire :/
02:35 tempire and look at that
02:35 tempire all tests pass
02:35 tempire \o
03:09 noganex_ joined #mojo
03:21 keedi joined #mojo
03:27 xaka joined #mojo
03:39 dvinciguerra joined #mojo
03:43 mattastrophe joined #mojo
03:52 * tempire wonders when marcus' mojolicious year in review blog post is coming
03:59 * sri bought Programming in Scala :o
04:06 hesperaux joined #mojo
04:07 hesperaux Hello. I don't know if anyone remembers me from last month, but I convinced my colleagues and boss to use mojolicious at work and they are loving it. ;D
04:09 anewkirk hesperaux, that'll be 12 shillings please
04:09 hesperaux lol
04:13 sri \o/
04:25 yakubori joined #mojo
04:49 xaka joined #mojo
05:07 rem_lex| joined #mojo
05:51 spleenjack joined #mojo
06:19 buu joined #mojo
06:55 dpetrov_ joined #mojo
07:03 buu joined #mojo
07:03 Caelum I got through half of the scala book, been meaning to finish it, very complex language, but a very nice language
07:09 salparadise joined #mojo
07:11 Vandal joined #mojo
07:33 dhg joined #mojo
07:35 ver joined #mojo
08:05 suy joined #mojo
08:16 dod joined #mojo
08:16 ab joined #mojo
08:27 suy joined #mojo
08:37 mattastrophe joined #mojo
08:38 dwierenga joined #mojo
08:49 dod joined #mojo
09:10 ObseLeTe joined #mojo
09:13 zivester joined #mojo
09:32 cosmincx joined #mojo
10:23 SmokeMachine joined #mojo
10:29 wircus joined #mojo
10:29 rbmntjs_ joined #mojo
10:29 wircus o/
10:47 SmokeMachine joined #mojo
10:54 SmokeMac_ joined #mojo
11:01 PanzerBjorn left #mojo
11:05 d4rkie_ joined #mojo
11:19 yakubori joined #mojo
11:19 cosmincx joined #mojo
11:38 SmokeMachine joined #mojo
11:41 SmokeMac_ joined #mojo
11:43 SmokeMa__ joined #mojo
11:58 SmokeMachine joined #mojo
12:00 SmokeMachine joined #mojo
12:01 SmokeMachine joined #mojo
12:04 SmokeMachine joined #mojo
12:06 SmokeMachine joined #mojo
12:09 berov joined #mojo
12:14 dbr joined #mojo
12:30 SmokeMachine joined #mojo
12:43 SmokeMac_ joined #mojo
12:46 SmokeMa__ joined #mojo
12:49 SmokeMachine joined #mojo
12:55 wircus sri: Should MOJO_USERAGENT_DEBUG really do this? https://www.evernote.com/shard/s22/sh/f7cbf0cd-f5d​1-4ef6-aa27-972cd3ca24cd/7856dd5bf4d425609c435a5ba​ed299bb/deep/0/Screenshot%2014.01.13%2013:49.jpg
12:55 wircus (when uploading an image)
12:56 SmokeMachine joined #mojo
12:57 SmokeMachine joined #mojo
12:59 nicomen would be cool to output something like: $ identify phone.jpg
12:59 nicomen phone.jpg JPEG 540x675 540x675+0+0 8-bit DirectClass 67.5KB 0.000u 0:00.019
13:00 nicomen +size
13:00 SmokeMac_ joined #mojo
13:00 vervain wiruc: I'll test locally, when you say upload, by what method?
13:08 vervain wircus: Mine certainly seems to output the the img data to console as well.  So I guess the answer is 'probably'.
13:08 vervain at least with a post_form method
13:11 Mike-PerlRecruiter_ joined #mojo
13:20 arthas_ joined #mojo
13:21 SmokeMachine joined #mojo
13:38 tm joined #mojo
13:38 judofyr joined #mojo
13:38 tm hi folks
13:39 judofyr hi tm
13:39 gryphon joined #mojo
13:39 tm I got stuck with something strange yesterday - I have /auth action, uses OAuth2 to google, works ok... kind of
13:40 tm after login I get data I need and set session, then if I redirect to / it stops working, but if I render static text it's ok
13:41 tm to be exact, if I do $self->redirect_to('/'); the whole controller is no longer being called when user clicks on auth :-(
13:41 SmokeMachine joined #mojo
13:41 tm like browser remembered that /auth redirects to / and ignores /auth from now on
13:41 tm is that possible?
13:42 tm browser/app restarts do not help, cache cleared, etc usual suspects eliminated
13:46 tm http://pastebin.com/05c6bY9E
13:49 tm anybody seen something similar before? I'd blame it on a browser - chrome pre-fetches URLs as you type btw :D
13:50 tm any ideas/suggestions more than welcome
14:00 nicomen could it be a permanent redirect?
14:01 nicomen http://stackoverflow.com/questions/1393280/ht​tp-redirect-301-vs-302-temporary-vs-permanent
14:01 tm app log says 302 in theory
14:02 tm another thing that got to me now, is that /auth is both trigger and callback for OAuth2 - will need to separate those and see what happens
14:03 SmokeMachine joined #mojo
14:09 tm ok, morbo says GET /auth -> 302 -> / - sadly OAuth doesn't happen at all
14:09 jnbek joined #mojo
14:11 sri hmm
14:11 sri think i'll deprecate Mojo::Util->html_escape
14:16 tm hmmm does Mojo cache responses? i.e.  same client requests the same URL, logic doesn't get called, old result is rendered?
14:23 judofyr sri: hm. why?
14:23 judofyr tm: nope
14:24 sri it's broken and i don't want to fix it :)
14:24 judofyr sri: hm… broken how?
14:24 sri doesn't support multi byte entities
14:24 judofyr ah, encodings
14:27 good_news_everyone joined #mojo
14:27 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/4iV0KQ
14:27 good_news_everyone mojo/master cec5010 Sebastian Riedel: deprecated Mojo::Util->html_escape and fixed support for multi byte entities in Mojo::Util
14:27 good_news_everyone left #mojo
14:27 suy joined #mojo
14:27 sri and of course, mojolicious doesn't actually use it
14:27 sri it's all xml_escape
14:27 judofyr tm: I have no idea really. we've been using the OAuth2-redirect-to-itself-with-code-parameter successfully
14:28 SmokeMachine joined #mojo
14:28 judofyr sri: maybe mention in the deprecation warning that xml_escape should be used?
14:29 judofyr sri: what do you think about the Perl-Dead-End-rewrite-in-Scala-Moe-project btw?
14:30 tm judofyr: exactly, all started failing when I added condition to set one or two session keys depending on database response (AgentID+AuthOK flag or just flag)
14:30 Molaf__ joined #mojo
14:31 tm judofyr: as soon as static text is rendered instead of redirect to any other page, all works, OAuth get's called and data comes down as planned
14:32 good_news_everyone joined #mojo
14:32 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/zB-tAQ
14:32 good_news_everyone mojo/master 20f254c Sebastian Riedel: mention xml_escape in deprecation warning
14:32 good_news_everyone left #mojo
14:32 judofyr tm: hang on, where do you render the text?
14:33 judofyr tm: you'll have to do it in the callback
14:33 * tm facepalms and hits his head against the desk
14:34 tm here's te bit http://pastebin.com/05c6bY9E
14:34 tm so all of that logic has to be in the callback then, not outside of it - arghhhhh
14:34 bluescreen joined #mojo
14:34 SmokeMac_ joined #mojo
14:34 judofyr tm: yes. you can also use Delay if you want to flatten it a bit: https://metacpan.org/module/​Mojolicious::Plugin::OAuth2
14:35 judofyr tm: the request is being done async, so the code below the ->get_token gets executed *before* the on_success-callback
14:36 tm judofyr: commented out async anyway - I saw the code running ahead of the callback
14:37 sri marcus, tempire, crab: see deprecation above, if you want it undone you will have to fix html_escape to work with multi byte entities ;)
14:37 judofyr sri: hm… what's the difference between xml and html escape?
14:38 sri http://mojolicio.us/perldoc/Mojo/Util#xml_escape
14:38 SmokeMa__ joined #mojo
14:42 tm judofyr: thanks for helping me with that - stupid brain fart with this bit but valuable lesson learned - thank you!
14:42 judofyr tm: async is hard ;)
14:42 sri lets go shopping
14:42 SmokeMachine joined #mojo
14:42 ObseLeTe joined #mojo
14:47 sri judofyr: btw. i just bought a scala book, that should answer your second question ;p
14:47 judofyr sri: :D
14:48 vervain scala is the only language that's attracted me away from perl for a while.  So I'm intrigued.
14:48 vervain At one point I went through the motions of Lift vs. Mojo :)
14:49 SmokeMac_ joined #mojo
14:51 judofyr heh, Scala does seem a bit Perl-like
14:55 SmokeMachine joined #mojo
14:56 ObseLeTe joined #mojo
14:57 davehorner joined #mojo
15:04 SmokeMac_ joined #mojo
15:07 SmokeMa__ joined #mojo
15:16 Britzel joined #mojo
15:22 tm another thing that bothers me - template at / renders some stash values in it... when user logs out i drop session by setting expire time in the past, then redirect to /
15:23 tm redirect ok, but app cries about variables in template needing explicit package name, like they didn't populate stash
15:23 tm I have to kill morbo and restart app - then all works
15:27 mst could we see the code please?
15:27 tm sure 1sec
15:28 mst since currently I know little more than "you have some perl, and it does an unexpected thing until you restart the process"
15:29 nicomen lol
15:32 SmokeMachine joined #mojo
15:32 tm mst: http://pastebin.com/UFsxwZFN :-)
15:33 tm code looks ok to me and this happens occasionally only, not always (for some reason) so I can't locate what I did wrong
15:34 mst argh, it's the buggy broken thing that eats perl code :(
15:34 mst also, you didn't show me all the code
15:34 mst where's %data from?
15:34 mst where's the template?
15:34 tm no no... it's just me screwing up simple things
15:34 mst where's the real, actual error message?
15:34 mst nono, pastebin.com is a buggy broken thing that eats perl code
15:35 tm relly?
15:35 tm ok, let me collate all bits and I'll come back later - prepared as I should :)
15:35 vervain tm: try stash($var) in your templates if there's a chance $var will not be set.
15:36 mst vervain: first, let's see if there's something to fix that means it always is set :)
15:36 tm vervain: tnx - written down for future reference
15:36 mst tm: but if it -should- be set, let's try and get it set :)
15:37 tm ;) error was of scope - need explicit package name - possibly another screwup like with OAuth earlier today :-/
15:38 tm let me work it out, if I won't find it I'll get all the bits of code, template, error and put up somewhere that doesn't eat code ;)
15:38 tm thanks for all your advice
15:40 * tm will be back later
15:50 * sri is wondering if it would be more sensible to switch xml_escape and html_escape, and then deprecate xml_escape
16:02 SmokeMachine joined #mojo
16:06 dhg joined #mojo
16:13 good_news_everyone joined #mojo
16:13 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/jPFGuA
16:13 good_news_everyone mojo/master 91a49f4 Sebastian Riedel: better url_unescape example
16:13 good_news_everyone left #mojo
16:21 SmokeMac_ joined #mojo
16:24 SmokeMachine joined #mojo
16:29 SmokeMac_ joined #mojo
16:35 inokenty joined #mojo
16:37 SmokeMachine joined #mojo
16:44 anaio joined #mojo
16:46 berov left #mojo
16:47 alester joined #mojo
16:48 SmokeMachine joined #mojo
16:51 SmokeMachine joined #mojo
16:57 rhaen_http joined #mojo
16:57 rhaen_http hej everyone.
16:58 rhaen_http uhm, just a short question: Is there a reason why Mojo::URL doesn't support file:/// ?
16:59 SmokeMac_ joined #mojo
16:59 yakubori joined #mojo
17:01 sri rhaen_http: no need for it in core
17:01 SmokeMac_ joined #mojo
17:03 rhaen_http That's a good answer :)
17:04 xaka joined #mojo
17:05 SmokeMachine joined #mojo
17:09 SmokeMachine joined #mojo
17:10 SmokeMac_ joined #mojo
17:18 SmokeMachine joined #mojo
17:20 SmokeMachine joined #mojo
17:22 SmokeMachine joined #mojo
17:26 SmokeMachine joined #mojo
17:37 dhg joined #mojo
17:37 good_news_everyone joined #mojo
17:37 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/uRY4lA
17:37 good_news_everyone mojo/master 622e241 Sebastian Riedel: add comments for all deprecated code
17:37 good_news_everyone left #mojo
17:39 SmokeMachine joined #mojo
17:44 good_news_everyone joined #mojo
17:44 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/nAHDvw
17:44 good_news_everyone mojo/master c2f218e Sebastian Riedel: deprecated Mojo::Home->slurp_rel_file in favor of Mojo::Util->slurp
17:44 good_news_everyone left #mojo
17:48 njlg joined #mojo
17:53 sri some Mojo::Util functions like b64_encode/decode, md5_bytes/sum, sha1_bytes/sum are also pretty redundant these days
17:54 sri they are from the time when we needed fallbacks for old perls
17:56 SmokeMachine joined #mojo
17:57 xaka joined #mojo
17:57 sri hmm
17:57 sri they seem to be in wide use, guess it's no big deal if we keep them http://grep.cpan.me/?q=use+Mojo%3A%3AUtil+
17:59 SmokeMachine joined #mojo
18:03 mst sri: maybe over time consider it to be a List::AllUtils like thing
18:04 amirite joined #mojo
18:04 amirite what response code am i supposed to send back in websockets?
18:05 amirite chrome complains about unexpected 200 code
18:05 dotan joined #mojo
18:07 sri mst: think i'd rather not :)
18:07 ka2u joined #mojo
18:07 sri mst: btw. you're missing in #moe
18:09 mst sri: because what I really need in my life is ANOTHER IRC CHANNEL
18:09 sjn joined #mojo
18:09 * amirite cries
18:09 sri and an active one at that ;p
18:10 SmokeMachine joined #mojo
18:13 jnbek joined #mojo
18:14 SmokeMachine joined #mojo
18:17 SmokeMachine joined #mojo
18:20 SmokeMachine joined #mojo
18:23 SmokeMachine joined #mojo
18:27 amirite websockets are supposed to return code 101 and not 200?
18:29 SmokeMachine joined #mojo
18:31 SmokeMachine joined #mojo
18:34 SmokeMachine joined #mojo
18:36 SmokeMachine joined #mojo
18:38 amirite how do i change the status code of a websocket
18:39 SmokeMachine joined #mojo
18:42 * tempire isn't concerned about html/xml_escape
18:43 SmokeMachine joined #mojo
18:43 tempire wircus: It would be awesome if DEBUG printed out a description of binary data instead of a dump.
18:43 tempire MAKE IT SO
18:44 tempire come to think of it, that would have been useful when debugging gzipped data recently
18:44 L23231231 joined #mojo
18:45 SmokeMachine joined #mojo
18:49 sjn joined #mojo
18:52 SmokeMachine joined #mojo
18:54 amirite u/me sighs
18:55 SmokeMac_ joined #mojo
18:58 sri tempire: useragent doesn't even know what is headers and what is body, i don't think it can be done
18:59 sri as a matter of fact, any developments in that direction could get in the way of http/2 support
19:00 sri so be careful
19:01 sri on the other hand, once we do have protocol channels, diagnostics will get easier and better
19:02 tempire That's the initial work you've been talking about to get ready for http2, right?
19:02 tempire (channels)
19:08 sri https://github.com/kraih/mojo/issues/423
19:08 sri yea
19:08 sri for diagnostics it would be pretty great
19:10 sri it's a 5.0 feature though unless volunteers start working on it
19:11 nicomen tought parsing mime/multipart stuff from the body might require external modules...
19:11 nicomen though
19:11 nicomen hm maybe not
19:15 rem_lex|pivo joined #mojo
19:18 sjn joined #mojo
19:19 SmokeMachine joined #mojo
19:19 L23231231 Hello
19:20 L23231231 can someone tell me if I have to create http://mojolicio.us/perldoc​/Mojolicious/Plugin/Config or does it already exists after creating an full app ?
19:22 L23231231 The cookbook says "Or just add a hypnotoad section to your Mojolicious::Plugin::Config", but it does not appear to be created
19:24 SmokeMac_ joined #mojo
19:26 amirite joined #mojo
19:26 L23231231 do I do "mojo generate plugin Config"
19:27 L23231231 after "mojo generate app MyApp"
19:27 jberger joined #mojo
19:28 jberger L23231231, no, you just need to set some defaults
19:28 * jberger looks for doc
19:28 ka2u joined #mojo
19:28 jberger http://mojolicio.us/perldoc/Moj​olicious/Plugin/Config#default
19:29 L23231231 but that only works in ::lite
19:29 jberger you its just showing the lite syntax
19:29 jberger s/you/no/
19:30 jberger $app->plugin('Config' => { default => {}});
19:30 jberger ::Lite is just a sugar layer
19:30 L23231231 So where does that go in the script or MyApp.pm module because I tried both
19:30 jberger btw that line would be in your startup
19:31 L23231231 ahh
19:31 L23231231 but $app = $self
19:31 L23231231 s/but/so/
19:31 jberger the ::Lite app is basically all wrapped into the startup method
19:31 jberger yes
19:31 jberger (by convention much of the docs us $app as an instance of the app, and $c as an instance of the controller)
19:32 jberger my typing is terrible today
19:32 jberger s/us/use/
19:33 L23231231 thanks, that worked :)
19:34 jberger good
19:34 jberger read Growing, it really helps when moving from ::Lite to full
19:34 L23231231 What code is executed in MyApp apart from startup
19:34 L23231231 I did read that
19:34 jberger in fact reading this and the next code is the best: http://mojolicio.us/perldoc/Mojolic​ious/Guides/Growing#Final_prototype
19:35 jberger anything that you call from startup
19:35 jberger :-P
19:36 SmokeMachine joined #mojo
19:36 L23231231 So in the full app, is that the place I define gets  puts routes etc..
19:37 marty And don't forget to view the mojocasts.    http://mojocasts.com
19:38 L23231231 I think my problem is understanding the call structure of the full app vs. ::lite
19:38 L23231231 I'm complete noobie at this :( sorry
19:39 jberger again, when you compare the link I just posted to the next code block later it shows that transition step
19:39 jberger but yes, its mostly "wrap your lite app in a sub named startup"
19:39 jberger (with some exceptions)
19:43 L23231231 ok so, I think I understand now, startup is not just the "pre init piece of code"; it like a call to "Main"
19:43 L23231231 and the only call
19:44 L23231231 ?
19:44 L23231231 unless I add code outside and call it from within startup
19:45 jberger yep, well said
19:45 L23231231 thanks.
19:49 sri tempire: perhaps something like this would be a good interim solution to the non-printable character problem http://pastie.org/5684481
19:51 sri (just a proof of concept, no actual proposal)
19:54 SmokeMachine joined #mojo
19:58 SmokeMac_ joined #mojo
19:59 amirite joined #mojo
20:12 SmokeMachine joined #mojo
20:22 L23231231 is it possible to change the operating mode from within initial startup? rather than -m command line, could I set ENV{MOJO_MODE}=Development for example
20:25 buu Yes?
20:26 buu Perl can in fact change environment variables.
20:28 jberger it might be too late though
20:28 L23231231 when I do this from startup "  $ENV{MOJO_MODE}="Development";"
20:28 tempire L23231231: why would you want to do that?
20:28 L23231231 ahh, that's what I  was thinking,
20:28 L23231231 because my log is saying production
20:29 L23231231 So it's either initial Environment or command line
20:31 basic6 joined #mojo
20:36 L23231231 I think you also need to spell Development in lower case else Development = production
20:41 Gedge joined #mojo
20:46 L23231231 Is it possible in Mojolicious to force logs (when in development mode) to stdout/stderr rather than the log file (e.g. logs/development.log); so that it works like the Mojolicious::Lite development
20:47 L23231231 only when using -f (forground option)
20:47 basic6 i have a hashref (containing strings with UTF8 characters) that i want to turn into a json string. i would expect the unicode characters to be encoded like "\uHEX", but they aren't. the docs say "encoding will only generate UTF8".
20:47 basic6 does this mean i have to encode my hashref (all strings in there) "manually" before i call $json->encode?
20:47 nicomen or encode the string
20:48 basic6 nicomen encode the resulting json string?
20:48 lukep joined #mojo
20:48 nicomen basic6: yes
20:48 nicomen normally you want to decode/encode when passing data in or out to something else, you want to do this as early and as late as possible at the outer ends of communication
20:50 nicomen ah wait, don't remember if mojos json encode/decode does this for you
20:51 basic6 nicomen what's the proper way to encode the resulting json string? probably something like Encode::from_to($bytes, FROM?, TO?)...
20:51 basic6 btw i've also tried to encode all the strings by converting the characters into their char codes (ord) and decoding this later, which worked perfectly but i thought there may be a better way
20:51 basic6 ...converting all the characters to their char codes *before* putting them into the hashref which is then json'ed
20:52 tempire L23231231: remove the log directory, and all logs will go to stdout
20:52 basic6 nicomen is it possible that i cannot rely on Mojo::JSON to always handle utf8 input characters correctly?
20:53 L23231231 Thanks handy, thanks.
20:54 L23231231 F!@#, I meant that's handy, thanks
20:57 basic6 maybe i'll take your advice to encode as early as possible and encode everything before passing it to Mojo::JSON, that way I'm sure it'll work.
21:05 sri Mojo::JSON expects perl characters, and will turn those into valid JSON, you don't have to encode anything
21:06 sri in fact, if you encode your data it will get double encoded
21:07 basic6 sri i know it would be double encoded and i don't really want that. but shouldnt the unicode characters be escaped after $json->encode?
21:08 sri i don't know what you're talking about, if it comes out of Mojo::JSON, it is valid JSON, end of story
21:08 sri perhaps you're misunderstanding something, JSON is a binary format, you don't mess with it at all
21:09 basic6 I should add that on the other end there's some javascript which uses JQuery to decode the json string into a js object. what used to be unicode characters are still separate bytes.
21:12 basic6 json should be able to handle unicode characters, i think - maybe jquery isn't decoding those multi-bytes into unicode characters as i expect
21:14 dminus joined #mojo
21:19 jberger basic6, I'm having that same issue
21:20 jberger https://github.com/jberger/Galileo/commit/fa​e9e63a22af087c9e6551d9f18922327bae2b15#L2R13\
21:20 jberger oops lose that last \
21:20 jberger https://github.com/jberger/Galileo/commit/fa​e9e63a22af087c9e6551d9f18922327bae2b15#L2R13
21:21 jberger I had to add a little function to make json from a hash, then decode it before sending it
21:21 jberger this is in my testing
21:22 basic6 jberger interesting i'm not the only one. assuming that jquery can't turn multibyte unicode bytes into real unicode chars, i've added $.ajax({scriptCharset:"utf-8"..., no change
21:22 jberger when I use the app, it behaves correctly, so I had to add this to my testing to adaquately test the real world
21:22 jberger from the app I'm sending a string by first doing JSON.encode
21:23 basic6 a 5 character string, where the 3rd char is a chinese character (i'm pretty sure it's 3 bytes long), but javascripts length attribute has the value 7...
21:28 basic6 oh...
21:32 xaka joined #mojo
21:33 basic6 okay that worked, but i don't really get it... so i'm json'ing my hashref (which then contains multiple bytes where i expect a unicode char (or something escaped but this isn't necessary)). then i decode the resulting string with Mojo::Util, just like you do.
21:33 basic6 to me it looks like $json->encode is simply returning multiple bytes (3 bytes for 1 chinese char, for example) and the decode funciton turns those multiple bytes back into unicode characters. but sri said Mojo::JSON is returning valid JSON so maybe i'm still somehow wrong...
21:34 dwery joined #mojo
21:35 rem_lex| joined #mojo
21:37 sri unicode is hard
21:37 basic6 i agree
21:38 rem_lex joined #mojo
21:40 nicomen basic6: so the multiple bytes for a chinese character is how utf8 encoding looks like
21:41 sri i've recently extended examples/websocket.pl btw. to demonstrate a correct unicode roundtrip
21:41 sri (with json)
21:41 jberger sri: will look, thanks
21:51 jberger sri: I'm not trying to be too skeptical, but the problem I'm having is an (apparent) inconsistency in how characters which are gotten from the browser (user) are sent versus how ones that are created from perl (testing) are sent
21:52 dwery joined #mojo
21:53 good_news_everyone joined #mojo
21:53 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/nVRRow
21:53 good_news_everyone mojo/master 0cedac1 Sebastian Riedel: add full JSON roundtrip to WebSocket example
21:53 good_news_everyone left #mojo
21:53 sri jberger: ok, now it's a complete roundtrip with decoding/encoding on both sides
21:53 sri and multi byte characters on both sides
21:54 sri https://github.com/kraih/mojo/bl​ob/master/examples/websocket.pl
21:57 nicomen jberger: make a small test case ;)
21:57 jberger yep, working on it now
21:57 jberger :-)
21:57 nicomen are you getting double encoded json?
21:57 good_news_everyone joined #mojo
21:57 good_news_everyone [mojo] kraih pushed 1 new commit to master: http://git.io/wrTM1g
21:57 good_news_everyone mojo/master 3c28daa Sebastian Riedel: cleaned up WebSocket example a little
21:57 good_news_everyone left #mojo
22:04 dhg joined #mojo
22:15 wircus <3
22:20 jberger I can't get my minimal example to fail like Galileo was doing
22:20 jberger which leads me to suspect DBIx::Class or SQLite was getting in the way
22:22 SmokeMachine joined #mojo
22:22 nicomen jberger: how did it fail?
22:23 jberger garbled unicode characters
22:23 nicomen jberger: that is most likely caused by reading in data without telling perl what encoding it uses
22:24 nicomen $ perl -MMojo::JSON -wle 'my $wrong_utf8 = "æøå"; print Mojo::JSON->encode($wrong_utf8);'
22:24 nicomen "æøå"
22:24 jberger there aren't too many failure points
22:24 nicomen wrong_utf is a perl string containing utf8 encoded data, but perl doesn't know it is utf8, when sent to encode() it prints each byte separately
22:25 nicomen if I tell it to decode from utf8, it works fine:
22:25 nicomen $ perl -MEncode -MMojo::JSON -wle 'my $wrong_utf8 = Encode::decode_utf8("æøå"); print Mojo::JSON->encode($wrong_utf8);'
22:25 nicomen "æøå"
22:25 jberger ok, I will check that
22:25 nicomen so if you are reading utf8 content from a database for instance without telling the database library that the content is utf8, you will get similar errors
22:26 basic6 nicomen could you also tell perl that this is utf8 instead of decoding it?
22:26 nicomen yes, but it is not encouraged
22:26 nicomen a) if it's for typing utf8 inside the source code, use utf8; works
22:27 basic6 i don't have utf8 in my source, it's all coming from a db
22:27 nicomen which db?
22:27 basic6 but let's assume it's coming from a text file which is utf8 encoded, so why not tell perl that this is utf8?
22:27 nicomen b) you can manually set the utf8 flag of a variable
22:27 nicomen basic6: you would tell perl that when reading the file ;)
22:28 nicomen open my $fh, "<:utf8", 'filename.txt';
22:28 nicomen that's what I meant decoding/encoding on boundaries (Mojo::JSON does it for you on the delivery end)
22:28 basic6 ok that's the flaw in my analogy.
22:29 nicomen which db are you using? which module?
22:29 basic6 DBIC
22:29 basic6 db is mysql
22:29 nicomen try this:
22:30 basic6 but here's the thing: if i let perl print the db output before i send it to json, its correct
22:30 nicomen http://search.cpan.org/~getty/DBIx-Class-0.08​204/lib/DBIx/Class/Manual/Cookbook.pod#MySQL
22:30 nicomen basic6: you only think it's correct ;)
22:30 nicomen you are printing the correct bytes in the correct order, and your terminal expects utf8, so they show fine
22:31 nicomen but perl is not treating it as utf8
22:31 basic6 "mysql_enable_utf8 => 1" already using that. before, unicode characters were in fact not correctly returned from the db (from dbic)
22:31 sri if printed unicode data looks right, it is most likely wrong :)
22:31 nicomen are you concatenating the results with strings from the source code?
22:31 basic6 no
22:32 nicomen hm
22:32 sri because odds are STDOUT is in binary mode and your data is already encoded (in binary form, not perl characters)
22:32 basic6 nicomen actually i haven't done a "real test" which would print it on my terminal directly - i've let perl die and viewed the output in the (utf8 encoded ) error 500 page
22:33 basic6 it's not utf8
22:33 basic6 well it is, of course. but not a utf8 char, mutliple bytes
22:34 nicomen use Data::Dumper to check your strings
22:34 nicomen $ perl -MEncode -MData::Dumper -wle 'my $wrong = "←↓→"; my $right = Encode::decode_utf8("←↓→"); print Dumper([$wrong, $right ])'
22:34 nicomen $VAR1 = [
22:34 nicomen '←↓→',
22:34 basic6 done that too, same thing
22:34 nicomen "\x{2190}\x{2193}\x{2192}"
22:35 nicomen ];
22:35 basic6 oh hold on
22:35 basic6 not the same thing
22:35 nicomen Data::Dumper should give you \x[..} for correctly flagged variables
22:36 dwery joined #mojo
22:38 basic6 i'm pretty sure, dumper encoded the unicode bytes like \xHEX
22:38 basic6 BUT: one time i've let perl die with both the original strings (containing utf8 chars) from the db (dbic) and the output of those strings as json. since i used die, i viewed it in a browser, http charset utf8, html charset utf8. (i know this isn't how you'd test things normally). the original strings were "correct", the json result was not.
22:38 bluescreen joined #mojo
22:38 dwery joined #mojo
22:39 nicomen basic6: Mojo::JSON prints bytes, but your html output might not have been properly encoded
22:40 basic6 nicomen then why were only the json result "wrong" (multiple bytes), not the original db output - both strings were next to each other in the same html error output
22:40 nicomen because the string was originally double encoded ;)
22:41 nicomen which could happen if you have inserted utf8 data into the db with utf8 turned off
22:41 nicomen then later turn it on
22:41 basic6 you mean the db itself might contain double encoded utf8?
22:41 nicomen might indeed
22:41 nicomen many people live with that unknowingly
22:42 basic6 that would be bad
22:42 SmokeMachine joined #mojo
22:43 basic6 nicomen so i just opened my db directly, got the content using plain sql and it all looks fine. my terminal is using utf8, so i guess that can't be it.
22:44 nicomen $ perl -MData::Dumper -MEncode -MMojo::JSON -wle 'my $double = "←↓→"; print $double; print Mojo::JSON->encode([$double]);'
22:44 nicomen ←↓→
22:44 nicomen ["←↓→"]
22:44 nicomen basic6: did you set utf8; before querying?
22:44 basic6 no, not really...
22:44 nicomen SET NAMES utf8;
22:45 nicomen SELECT ...
22:45 basic6 that doesn't change anything
22:45 basic6 it's all correctly displayed on my terminal
22:45 nicomen ok, good
22:46 nicomen then I would use the Dumper thing to print it all the way from retrieving till sending it out
22:46 basic6 again i'm still confused by the fact that one single die with both, the original string from the db and it's json result showed the characters correctly in the orignal string but not in the json result
22:46 nicomen basic6: but isn't my last one-liner exactly that?
22:48 basic6 nicomen oh it is, i didnt see that
22:48 nicomen $ perl -MEncode -MMojo::JSON -wle 'my $double = "←↓→"; print "utf8: " . (Encode::is_utf8($double) ? 1 : 0); print $double; print Mojo::JSON->encode([$double]);'
22:48 nicomen utf8: 0
22:48 nicomen ←↓→
22:48 nicomen ["←↓→"]
22:51 basic6 but doesn't it make a difference that you're not using utf8? i mean Encode::is_utf8(originalstringfromdb) is 1 for me
22:53 basic6 and Encode::is_utf8($bytesjsonresult) is false
22:54 jberger anyone know if dbish outputs unicode?
22:54 basic6 to me it looks like dbic is returning correct utf8 characters with the utf8 flag on, but after this goes thru json-encode, the flag is off and the unicode chars are mutliple bytes
22:54 nicomen that is correct
22:55 basic6 so i'm not saying Mojo::JSON is doing it wrong, but i expected the output to also be utf8 (flag set to on)
22:55 nicomen the json structure is bytes, and it needs to be served with application/json; charset=utf8
22:55 dwery joined #mojo
22:55 nicomen but I thought you said you were doing that
22:56 dwery joined #mojo
22:57 sri basic6: that's exactly backwards, if the utf8 flag is on that data is *NOT* UTF-8 encoded :D
22:58 sri don't ever use the utf8 flag unless you know exactly how it works
22:58 sri is_utf8 is completely useless for you
23:00 basic6 sri so that was a wrong assumption how i thought it should work. thanks for clearing that up. i must have an error on the receiving end. i think i'll take a break, it's probably something obvious which i'm not seeing because i'm so focused on Mojo::JSON...
23:01 sri but seriously, ignore everything about encodings, there is basically just bytes and characters in perl, when you're working with data you want to make sure it is characters
23:01 sri how perl represents characters internally is irrelevant
23:03 sri you work with characters, and input/output bytes, modules like Mojo::JSON will do that transformation for you
23:04 jberger would love to keep working on this, but I gots to go, will check in later
23:06 sri JSON can only be bytes, since it has to be UTF-8 *encoded*
23:06 SmokeMachine joined #mojo
23:15 Averna joined #mojo
23:25 ObseLeTe joined #mojo
23:54 davehorner joined #mojo
23:56 jzawodn joined #mojo

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