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

IRC log for #mojo, 2015-04-01

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

All times shown according to UTC.

Time Nick Message
00:07 mattastrophe joined #mojo
00:27 frederico joined #mojo
00:42 zivester joined #mojo
00:42 asarch joined #mojo
00:42 sri wow, that's impressive for a self-published book https://www.discovermeteor.com/
01:01 GabrielVieira joined #mojo
01:19 shadowpaste "k-man" at 217.168.150.38 pasted "add input fields to an html table" (13 lines) at http://paste.scsys.co.uk/470914
01:19 k-man so thats my approach to adding an input field to an html table generated by HTML::Table::FromDatabase
01:20 k-man i'm sure there would be a better way?
01:21 k-man i suppose i could do it in the sql
01:22 sri there are not many nice things i could say about that approach
01:22 Zoffix They way I'd approach that problem is give the results of the database to the template and output HTML that way instead of mixing inside code :S
01:23 k-man sri, ok, i know its not good... i'm asking for advice
01:23 sri what Zoffix said
01:23 k-man Zoffix, ok
01:24 k-man so write some code in the template to itterate throgh the data and produce the table?
01:24 Zoffix yeah
01:24 k-man ok, let me try that
01:24 sri i've released examples for how i approach the separation of concerns problem in the blog example here https://metacpan.org/release/Mojo-Pg
01:24 k-man sri, thanks I'll have a look
01:24 * sri accidentally that sentence :S
01:26 Grinnz k-man, "code to iterate through the data and produce the table" is also just known as a "template loop", though with .ep templates it's a little more obvious that it's a perl loop
01:26 hshong joined #mojo
01:26 sri what database are you using?
01:27 k-man microsoft sql through DBI::Sybase (don't hate me, its what the accounting system uses here)
01:28 Grinnz oh god... sounds fun
01:28 k-man the fun part is bypassing our accountint system's UI :)
01:28 k-man we have to make fun where we can
01:29 genio mmm. ramen
01:30 genio DBD::Sybase has caused nothing but annoyance for me.  We use DBD::ODBC now
01:30 k-man genio, oh
01:30 genio k-man: install unixodbc and freetds and you're good
01:31 k-man genio, ok, I'll check it out
01:31 genio https://gist.github.com/genio/7c7fc52fcb8be5d486aa
01:31 genio k-man: There you go ^^
01:43 k-man my linux box is 64 bit but the sql server is 32 bit
01:45 k-man i think I'm running into issues there
01:45 genio doesn't matter
01:48 k-man actually, i think i have been down this path before
01:48 k-man checking some old code i have for a differente project
01:55 klapperl_ joined #mojo
02:10 shadowpaste "k-man" at 217.168.150.38 pasted "DBD::ODBC fails to install" (47 lines) at http://paste.scsys.co.uk/470916
02:10 k-man maybe because i am running perl threaded?
02:12 doby joined #mojo
02:18 noganex joined #mojo
02:26 kaare joined #mojo
02:28 jb360 joined #mojo
02:35 sri hahahahahaha http://www.ponyos.org/
02:38 Zoffix :O
02:39 Zoffix I love the "What are people saying about PonyOS?" section :)
02:39 Zoffix Well, I must try it out :D
02:40 Zoffix It's got doom!!!
02:40 * Grinnz wonders if there's actually anything reasonable that can be done about BSDs failing random POE::Loop::EV tests under kqueue
02:41 Grinnz i already disabled the readwrite test because that was consistently failing, but none of the other failures seem consistent...
02:42 k-man oof, got it workign finally
02:42 k-man had to build DBD::ODBC by hand to ensure the -x argument was passed to Makefile.PL
02:43 Grinnz eugh
02:43 k-man theres probably some trick to make cpanm do it
02:43 Grinnz well, you'd make EUMM or MB do it with env vars, i think
02:43 Grinnz not sure...
02:44 tianon joined #mojo
02:44 Grinnz its a EUMM dist
02:45 Grinnz so my guess is you could do PERL_MM_OPT="something added here" cpanm DBD::ODBC
02:45 k-man fair enough
02:45 GabrielVieira joined #mojo
02:45 k-man and i did get ODBC working once before, i just forgot. my test program I wrote ages ago works (once I fixed DBD::ODBC)
02:49 jberger <3 ponyos
02:55 GabrielVieira joined #mojo
03:00 jlrueda joined #mojo
03:07 GabrielVieira joined #mojo
03:13 k-man ok so back the the original question, how do i loop over a dataset in the template?
03:13 tianon joined #mojo
03:17 k-man like this example given here: http://blogs.perl.org/users/joel_berger/2012/10/a-simple-mojoliciousdbi-example.html
03:19 bpmedley k-man: Sorry for my lack of context, you want to loop over the dataset returned from DBI in a template?
03:19 GabrielVieira joined #mojo
03:24 k-man bpmedley, well.... i want to produce html tables from the dataset returned from dbi...
03:25 k-man and probably generate some <input> fields in that table...
03:25 bpmedley k-man: I must be confused.  It looks like that’s exactly what the blog post is doing.
03:26 k-man ok...
03:26 k-man thats fine, i just wanted to confirm that's what you mean
03:26 bpmedley k-man: Specifically: “% while (my $row = $sth->fetchrow_arrayref) {“   <— does this block of code make sense?
03:27 k-man yes it does
03:28 k-man i guess i was confused because the only templateing experince I have is Template Toolkit, and thats a bit more abstracted from perl, so it has its own looping syntax
03:28 k-man so iwas thinking there was some looping syntax for mojo templates, but i get it now, its just perl
03:28 bpmedley k-man: Hrmm.  There’s a lot to take in.  How much Mojo experience do you have?
03:28 k-man about 30 minutes or so ;)
03:29 bpmedley k-man: Cool stuff.  Took me a while to wrap my brain around it.  I see your question now; I believe you  are correct.  The looping syntax is perl.
03:34 Zoffix k-man, yeah, mojo's ep is just Perl.
03:35 Zoffix "my $row = $sth->fetchrow_arrayref" looks yucky to me. I'd probably abstract it away, so if I ever switch the model to something else, the template would still be good.
03:36 Zoffix If there ain't a lot of data in the database, I'd just dump it all in an arrayref and give that arrayref to the template :)
03:36 k-man i think i want to use a hash
03:37 k-man the "edited" example below might be improved
03:37 k-man return $sth->fetchall_arrayref
03:38 sri Zoffix: first you have to be sure that the DBD module doesn't actually fetch all results at once anyway
03:39 sri like DBD::Pg, which never uses a cursor, ever
03:39 Zoffix I've been using ->selectall_arrayref() for ages and it's the only thing I know about DBI :)
03:40 sri yea, trying to fetch one row at a time seems silly
03:40 Zoffix :)
03:47 k-man whats the difference between fetchall_arrayref and selectall_arrayref?
03:49 sri perldoc DBI
03:49 k-man nm, worked it out
03:49 Zoffix k-man, the former is called on a statement handle and the latter is on the db handle
03:51 Zoffix k-man, my $data = $dbh->selectall_arrayref('SELECT * FROM `your_db`', { Slice => {} });   then give $data to your template and loop over it... You'll have $_->{foo}, where 'foo' is the name of the column for each data cell
03:52 Zoffix So your markup would be html table head/footer and the loop innards would contain a <tr> with a <td> for each cell, and one <td> for that <input> you wanted to add
03:52 * sri would get so frustrated if he had to use the actual DBI api without abstraction
03:52 k-man oh ok
03:52 * Zoffix is reminded he still needs to properly learn DBIC and stuff
03:53 preaction i've been using DBIC for the first time in a while, and it's amazing. so much nicer than all our NIH crap...
03:54 Zoffix I've got one or two apps written using it at $work.. Pretty cool, but the learning curve is something to get through :|
03:54 Zoffix (especially since I only know basic SQL)
03:55 preaction that's fair. SQL itself is not always a picnic. and then database schemas usually take advantage of db-specific features, which leads to... complications...
03:55 Oleg joined #mojo
03:55 preaction easiest way to test models is to spin up a quick SQLite database, except when your queries require db-specific functions/features...
03:56 preaction then you're detecting database engines and altering queries and... yeah...
03:56 * sri is still learning SQL
03:56 k-man thanks Zoffix
03:56 Zoffix np
03:57 sri i'm a sucker for json support in postgresql though
04:00 sri so nice to have a basic table and then tack on a json field for arbitrary metadata you can make up later
04:02 sri this watered down lowest common denominator SQL you can use with a bunch of databases just doesn't work for me anymore
04:03 GabrielVieira joined #mojo
04:03 bpmedley Welcome to the world of vendor lockin.. ;)
04:11 k-man http://ix.io/hfc
04:11 k-man thats's my attempt with the column names
04:14 bpmedley k-man: Is it working?
04:14 k-man no
04:15 k-man hang on, i fixed incorrect placement of quotes
04:15 bpmedley Would you consider creating a Mojolicious::Lite example?
04:15 k-man that is mojolicious lite... do you mean can I paste a working example?
04:15 bpmedley Please
04:15 bpmedley Or, as much of a working one as you can.
04:17 k-man trouble is it queries my mssql database
04:17 k-man so I'd have to set up some other data source somehoe
04:18 bpmedley Perhaps, just stub the db connect string, I have a feeling we won’t need the actual data.
04:20 inokenty-w joined #mojo
04:25 bpmedley_ joined #mojo
04:33 sri "foreach" is just an alias for "for" and therefore rarely used
04:36 * Grinnz likes it better in the block form
04:36 sri this one is good too https://com.google/
04:36 Grinnz hahaha
04:37 sri best use of a new tld i've seen yet!
04:38 Grinnz the whois lookups annoyingly will not accept com.google :P
04:38 Grinnz aha found one that works
04:39 Grinnz registered by google registry, naturally
04:43 sri why would you use foreach over for?
04:43 sri it's more typing and not even a real word
04:43 Grinnz neither is elsif :P
04:44 Grinnz "foreach loop" is a recognized thing, it helps make it distinct from the stupid C for loops imo
04:44 sri i like for because it looks like for/in
04:44 sri for my $foo (@bar) {...}
04:44 sri i read that as "for my $foo in @bar"
04:46 Grinnz http://en.wikipedia.org/wiki/Foreach_loop
04:46 Grinnz the "each" makes it explicit that it's doing something to each element, instead of iterating with some counter
04:47 preaction but the @array also makes it pretty obvious what's happening
04:47 Grinnz it's a preference thing, not a clarity thing
04:47 Oleg in the CamelBook they recommend to use "foreach" when you mean "foreach", but i also always use "for"
04:48 sri well, perl6 doesn't appear to have a foreach, so i guess larry changed his mind ;p
04:50 * sri tends to assume a beginner wrote something if the word "foreach" appears
04:51 * Grinnz is still gonna use foreach everywhere :P
04:51 bpmedley A lot of newbies do like how foreach “reads” vs for.
04:51 Adura That's 4 more bytes.
04:51 Grinnz if i cared about bytes i'd be writing C
04:52 sri and get rid of that indentation...
04:52 Grinnz hey, my tab indentation is less bytes!
04:52 Grinnz <_< >_>
04:55 * Oleg using tab indentation everywhere
04:55 tianon joined #mojo
04:57 Phil21 what's wrong with foreach? :(
04:58 Adura 4 more bytes.
04:58 Phil21 ha, ok
04:58 Phil21 it's just old habit for me
04:58 Phil21 wonder why
04:58 sh4 joined #mojo
05:00 sh4 joined #mojo
05:16 tianon joined #mojo
05:29 k-man bpmedley, http://ix.io/hff
05:45 dod joined #mojo
05:48 melo joined #mojo
05:50 dod joined #mojo
06:04 jb360 joined #mojo
06:18 melo joined #mojo
06:28 dotandimet joined #mojo
06:48 trone joined #mojo
06:52 arpadszasz joined #mojo
06:56 fhelmber_ joined #mojo
07:11 dod joined #mojo
07:16 eseyman joined #mojo
07:25 eseyman joined #mojo
08:17 Vandal joined #mojo
08:34 Shaeto joined #mojo
08:59 espent joined #mojo
09:02 espent joined #mojo
09:14 dod joined #mojo
09:15 meshl joined #mojo
10:18 mattastrophe joined #mojo
10:20 mattastrophe joined #mojo
10:24 amon joined #mojo
10:59 batman any assetpack users who have input on this? https://github.com/jhthorsen/mojolicious-plugin-assetpack/pull/46
10:59 trone_ joined #mojo
11:03 riche batman: less disk I/O == great option
11:06 batman riche: hm... i guess i should add an option to _never_ make assets on disk then
11:06 batman :)
11:06 riche perhaps!
11:06 purl then again, perhaps not
11:06 riche purl: your opinion does not matter
11:06 purl riche: huh?
11:24 KCL joined #mojo
11:28 stl joined #mojo
11:29 tianon joined #mojo
11:35 Shaeto left #mojo
11:35 frederico joined #mojo
11:52 juikuen joined #mojo
12:05 mattastrophe joined #mojo
12:07 dod joined #mojo
12:13 neilhwatson joined #mojo
12:15 frederico joined #mojo
12:34 zivester joined #mojo
13:04 riche Folks - Mojoconf individual sponsorships are now available.  The individual sponsorship includes training and conference pass.  email hello@mojoconf.com if you're interested.
13:11 cpan_mojo Mojolicious-Plugin-AssetPack 0.46 by Jan Henning Thorsen - http://metacpan.org/release/JHTHORSEN/Mojolicious-Plugin-AssetPack-0.46
13:31 gryphon joined #mojo
13:32 bpmedley_ joined #mojo
13:42 jabberwok joined #mojo
13:52 asarch joined #mojo
14:10 OmarOthman joined #mojo
14:10 meshl joined #mojo
14:16 GabrielVieira joined #mojo
14:23 xevz joined #mojo
14:35 Ptolemarch joined #mojo
14:37 zackiv31 joined #mojo
14:47 sri not a bad first attempt to implement http/2 https://github.com/kraih/mojo/issues/423#issuecomment-88387983
14:49 Kripton joined #mojo
14:54 fallingup joined #mojo
14:56 sri biggest problem is the cgi env step, making it not work with non-blocking stuff
14:57 sri npn/alpn support seems reasonable
14:58 sri i guess that part could be made commitable pretty easily already
15:01 frederico joined #mojo
15:06 Ptolemarch joined #mojo
15:06 cpan_mojo Mojolicious-Plugin-LinkEmbedder 0.21 by Jan Henning Thorsen - http://metacpan.org/release/JHTHORSEN/Mojolicious-Plugin-LinkEmbedder-0.21
15:10 sri right, and support for concurrent streams is missing because it expects the response to be ready right away
15:15 fhelmber_ joined #mojo
15:21 jberger I'm not sure where to ask, so I'll ask here
15:21 jberger does anyone have a favorite module for printing things to dead trees?
15:21 jberger or do people just open a pipe to lpr?
15:24 batman what is "dead trees"?
15:24 Grinnz_ actual printers :P
15:24 pink_mist paper, generally
15:24 batman haha. ok :)
15:24 Grinnz_ i honestly barely print anything, nevermind from perl
15:25 jberger Grinnz_: same, which is why I have no opinions on modules for doing so :-D
15:25 Grinnz_ in unix i would look for something related to cups, but i'm not sure about cross-platform
15:25 Grinnz_ i would assume that you'd get that functionality from a toolkit you're using for GUIs
15:25 jberger this is for $work, I don't need cross-platform
15:25 batman jberger: i considered making something fancy, but i ended up not, simply because i didn't want my webserver to run as the same user as the print-whatever-thing
15:25 jberger batman: right, this is going to be from Minion probably
15:26 batman i might have missed out on something though
15:26 fallingup left #mojo
15:26 batman there are some lpr modules on cpan though...
15:26 jabberwok man -t Mojolicious::Guides::Rendering | lpr -o Duplex=DuplexNoTumble    # and then GBC comb-bind
15:27 batman i'm actually going to buy a printer i may. haven't had a printer since 2002 :)
15:27 jabberwok dead-tree is still the best format for learning and review: how do you scribble on a PDF?
15:27 Grinnz_ heh
15:28 batman i don't scribble. i just do.
15:28 batman ;)
15:29 batman jberger: did you catch the new linkembedder earlier? https://metacpan.org/source/JHTHORSEN/Mojolicious-Plugin-LinkEmbedder-0.21/Changes
15:30 jabberwok hmm, is there a fairly standard PostScript module? when last i actually had to print things like invoices and packing labels, I had to roll my own.  PostScript is modern-day FORTH... with somewhat Perl-esque dictionaries=symbol_tables. strange bizness.
15:32 jberger jabberwok: I would have PDFs anyway
15:32 jberger so I don't need to roll the ps on my own
15:32 jberger thank gods
15:33 jberger batman: I did see it go by
15:33 * jberger reads changes
15:33 jberger I hadn't seen ix.io
15:34 batman it's rather clever. someone used it in the channel earlier.
15:34 * batman can't remember who :(
15:34 Grinnz_ https://metacpan.org/pod/Net::CUPS if you have printers set up in cups, perhaps
15:35 jberger looks a bit like sprunge.us
15:35 jberger which I added to Mojolicious::Command::nopaste a while back
15:37 batman indeed. open an issue if you want me to add it to linkembedder :)
15:37 batman it = sprunge
15:37 jberger batman: how does it do the embedding? iframe?
15:38 jberger or is it just a pretty link?
15:38 asarch Any CRUD module for Mojolicious?
15:39 riche asarch: there are no cruddy mojolicious modules, they are all awesome
15:39 batman jberger: <pre>...</pre>
15:39 jberger riche++
15:39 asarch ...
15:39 jberger asarch: I've seen a few
15:39 asarch ?
15:40 jberger asarch: since Mojolicious doesn't have a specified database/datastore I think you probably just mean Rest frameworks
15:40 jberger of which there are a few
15:41 jberger you get to hook up the db parts though
15:42 tianon joined #mojo
15:43 asarch I thought DBIx::Class was Mojolicious de facto DB handler
15:43 batman asarch: it's not very "mojo", but it's an ORM
15:44 batman Mojo::mysql and Mojo::Pg is async (more mojo-ish), but does not provide an ORM
15:46 Dandre joined #mojo
15:49 mst asarch: Mojo::Pg and Mojo::mysql aim for lower level raw SQL async stuff
15:49 mst asarch: so if you need to do lots of simple stuff in parallel, they're awesome
15:50 mst asarch: then if you're trying to do complicated stuff, you probably want something higher level
15:51 asarch Oh :-(
15:54 asarch On the contrary, I was looking for something easier
15:54 asarch Anyway, I just was wondering
15:54 Grinnz_ "higher level" is generally "easier" to the end user
15:54 disputin joined #mojo
15:54 Grinnz_ e.g. perl is higher level than C
15:55 asarch Yeah, I know but actually from the point of view of the developer
15:55 asarch 1-2-3 and it's done
15:56 cpan_mojo AproJo 0.011-TRIAL by Helmut Wollmersdorfer - http://metacpan.org/release/WOLLMERS/AproJo-0.011-TRIAL (depends on Mojolicious)
15:59 pink_mist I'm pretty sure by 'user', Grinnz_ meant the developer.
16:03 OmarOthman joined #mojo
16:11 amon joined #mojo
16:17 Oleg joined #mojo
16:22 sri asarch: if you're looking for examples, Mojo::Pg ships with a cr(u)d example app https://metacpan.org/release/Mojo-Pg
16:23 asarch Thank you
16:23 asarch Thank you very much sri :-)
16:24 sri it's really too bad we can't ship a version of the blog example with mojolicious core
16:31 sri actually, i think i'll make the blog example full crud
16:49 Grinnz_ sri: Mojo::SQLite!
16:52 sri ?
16:52 Grinnz_ in mojo core, as a native db obviously ;)
16:53 sri no
16:54 dotandimet joined #mojo
17:03 dod joined #mojo
17:06 sri hmm, full crud example is quite a bit bigger
17:07 sri but it shows more best practices
17:07 genio I'm in favor of larger examples if they show more best practices.
17:15 dotandimet1 joined #mojo
17:16 sri full CRUD https://github.com/kraih/mojo-pg/commit/558fdd9bbb29c5544acc9a89254d1905b712fb07
17:16 punter joined #mojo
17:16 sri feedback welcome, i'm not entirely sure what best practices exactly we should encourage
17:19 sri i'm also emphasizing the separation of concerns part with the index method
17:19 sri previously the template used $c->posts->all, now the index method prepares the stash
17:20 sri every route has an action now
17:20 sri validation and form are shared
17:36 * sri hopes it's not in tldr territory now
17:40 doby sri: that's about as small as you can make a full CRUD example
17:40 doby looks solid to me
17:45 sh4 joined #mojo
17:59 dotandimet joined #mojo
18:02 OmarOthman1 joined #mojo
18:07 jayis joined #mojo
18:07 frederico joined #mojo
18:12 jabberwok sri++  blogcrud
18:15 berov joined #mojo
18:18 mattastrophe joined #mojo
18:30 Ptolemarch joined #mojo
18:43 nolbuk joined #mojo
18:47 hernan604 joined #mojo
18:49 riche ALL: although the Mojoconf abstract deadline was yesterday, you can still get your abstract in today!  Would love to see some killer use cases!
18:51 dotandimet joined #mojo
18:54 punter joined #mojo
19:12 nolbuk joined #mojo
19:21 noganex joined #mojo
19:31 * Grinnz_ wonders who keeps trying the EventEmitter chat he linked two days ago
19:34 cpan_mojo Rex-Repositorio 0.7.0 by Jan Gehring - http://metacpan.org/release/JFRIED/Rex-Repositorio-0.7.0 (depends on Mojolicious::Commands)
19:54 irctc114 joined #mojo
20:18 dotandimet joined #mojo
20:20 Ptolemarch joined #mojo
20:33 punter joined #mojo
20:37 dotandimet joined #mojo
20:40 mattastrophe1 joined #mojo
20:42 sri purl: no, browsers are http://rs1img.memecdn.com/FirefoxChrome-And-Internet-Explorer_o_91663.jpg
20:42 purl okay, sri.
20:43 jberger hehehe
20:45 _dave_ lol
20:57 meshl joined #mojo
21:00 batman sri: how about if i launched the blog example on a digitalocean host?
21:01 sri batman: i don't think anyone would want to look at it, there is no design at all
21:02 batman that's true...
21:02 batman i will have a quick look and see if i can use bootstrap or something
21:07 sri it's super boring, and people will just vandalize it
21:07 cpan_mojo joined #mojo
21:07 sri setting it up yourself is a better exercise
21:07 batman ok. how about the chat example?
21:08 sri just as boring
21:08 batman okidoki
21:08 sri and there is now a chat.pl in core that works everywhere
21:08 sri https://github.com/kraih/mojo/blob/master/examples/chat.pl
21:15 mattastrophe joined #mojo
21:51 Grinnz_ joined #mojo
22:13 serentiy hi, I am struggling with some mojo concepts.  I have a web-app that has two different types of websocket clients.  one type is a client/server style command and control.  a device connects to a websocket, and recv's instructions.  he basically waits persistently and when the server sends him a request he does it and replies.
22:14 serentiy the other websocket is browser based, clients see a list of "devices" whch are the websockets mentioned above.  I want the browser based clients to be able to interact and send messages via click, url, etc to the first websockets and get back useful data
22:14 serentiy I am struggling with how one set can see the other and message between them
22:15 sri use a message bus https://github.com/kraih/mojo-pg/blob/master/examples/chat.pl
22:15 serentiy thank you sir, I am off to read
22:17 serentiy does that require the use of postgres?
22:18 sri any message bus will do
22:19 sri purl: pubsub?
22:19 purl pubsub is what got me hacking on PCJ in the first place :)
22:19 sri purl: no, pubsub is http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern
22:19 purl okay, sri.
22:21 serentiy will all websockets of any style always have access to $self->pg?  this example has both in the same callback..  I am not seeing how to leverage this.
22:21 Grinnz_ serentiy: you can use Mojo::Pg or Mojo::Redis2 to do this easily
22:21 Grinnz_ "of any style"?
22:21 sri that specific example does not solve your problem, it demonstrates the pattern that will
22:21 Grinnz_ $self->pg is a helper that example creates
22:21 serentiy looks like, in browser based webchat, callback message .. pg->pubsub->notify(mojochat => shift), will take the browser data, publish to "subscription" named mojochat
22:22 sri which is a message bus/message queue/pubsub pattern...
22:22 Grinnz_ so it's available to any controller
22:22 sri funny how pubsub seems to be the answer to all websocket problems
22:22 serentiy pg->pubsub->listen(mojochat => sub { $c->send(pop) }); .. listens to pubsub "subscription" mojochat, pop being what the browser said
22:23 Grinnz_ thats what people want to use websockets for, communication with other websockets
22:23 sri purl: pubsub is also at https://github.com/kraih/mojo-pg/blob/master/examples/chat.pl
22:23 purl okay, sri.
22:23 Grinnz_ right, in that case it echos the string verbatim back through the websocket; you may need to do something more complex with it
22:23 serentiy so if I have users on a control websocket, and they submit values of "pc3" "do useful thing", the devices on a client websockets all subscribe to this bus.  if they listen they should see these messages
22:24 sri correct
22:24 Grinnz_ (i usually use json encoded messages)
22:24 serentiy if they know they are "pc3", they can do the useful thing
22:25 Grinnz_ they will only get messages on the channels they've subscribed to
22:25 Grinnz_ channel being the first arg to listen or notify
22:26 sri those examples would look a lot nicer with signatures
22:26 Grinnz_ heh
22:26 serentiy ok, so each of the client websockets can only subscribe to say a channel of their serial number or the like.  and browser websockets can reference that in the json, which the browser based websocket code would then publish on that channel
22:26 sri all the shift/pop stuff would be replaced with meaningful names
22:27 Grinnz_ you can manage channels however you like, but the general idea is to make it so you only have to do one notify to send a message to everyone on that channel
22:28 Grinnz_ then each subscriber's callback will determine how they respond to that message
22:28 sri purl: pubsub is also at http://redis.io/topics/pubsub
22:28 purl okay, sri.
22:29 serentiy thank you.  is "pg->pubsub->listen()" a blocking call?  could I have them subscribe to multiple channels?
22:29 Grinnz_ https://metacpan.org/pod/Mojo::Pg::PubSub#listen
22:29 Grinnz_ it is blocking, there's no async callback
22:30 Grinnz_ but the blocking there doesnt usually matter
22:30 Grinnz_ if you mean "does it block until it gets a message" then no
22:31 Grinnz_ and yes, you can subscribe to as many as you want
22:34 serentiy does this work on hynotoad / pre-fork servers?
22:34 Grinnz_ yes, that's why you'd use an external db for this like Pg or Redis2
22:34 serentiy this is bad ass..
22:34 Grinnz_ indeed
22:35 serentiy quick question, does Mojo::Pg->new('postgresql://postgres@/test') };  actually require I setup a pg database elsewhere or is it internal to the library?
22:35 Grinnz_ yes, you need a postgres server running
22:35 Grinnz_ that's what transmits the messages
22:36 serentiy hrmm
22:36 Grinnz_ redis can be a lighter setup if you don't need the relational database part
22:36 Grinnz_ but that also needs to be running
22:36 serentiy actually I do, but have been using sqlite.  I guess I am changing that as well.
22:37 Grinnz_ postgres scales much better when you are using a prefork server
22:38 Grinnz_ then you can use the same $pg for everything :)
22:39 serentiy not too sure about the syntax in that postgress URI, would I need to create tables specifically?
22:39 serentiy new to Pg
22:40 Grinnz_ the URI is just for the connection; it's just postgresql://<user>:<password>@<host>/<dbname>
22:41 Grinnz_ the rest of the stuff, you might want to start getting familiar with the postgres docs, http://www.postgresql.org/docs/9.4/static/index.html
22:41 Grinnz_ (and make sure you are using 9.4!)
22:42 serentiy I think the entire framework just clicked in my head.  have work to do.  thank you so much
22:54 sri pubsub in postgresql does not require any tables btw.
22:55 sri it uses a 2gb (last i checked) shared memory cache
22:55 Grinnz_ it requires a database though right? (otherwise it can't even connect iirc)
22:55 sri yes
22:57 sri and most of my examples that do require tables tend to create them automatically on startup with migrations
22:57 Nemix same for me...sqlite meets my requirements but need to move to a pub sub approach...going to be running on a odroid c1 (smallish computer) and close to rationalizing postgres
22:58 sri although, that's still a very new pattern, and i'm not sure where to go with it yet
22:59 sri redis and postgresql have both been pretty nice for pubsub
23:00 sri only thing you might stumble about is the 8kb size limit for messages
23:00 sri s/about/over/
23:01 sri but if you need more you can just store it in a table
23:03 sri (the limit appears to also be configurable though)
23:04 sri i really want to like that new macbook... but in benchmarks it is as slow as a 2011 macbook air :S
23:05 _dave_ argh really?
23:05 _dave_ I'm getting a new macbook soon
23:05 _dave_ I have a fair amount of trepidation in doing so
23:05 Grinnz_ redis is amazing, as long as you dont want to use it for relational data querying ;)
23:06 Grinnz_ but just pubsub, and "here's some data to store", it does great
23:12 good_news_everyon joined #mojo
23:12 good_news_everyon [mojo] kraih pushed 1 new commit to master: http://git.io/jpM9
23:12 good_news_everyon mojo/master 05fa333 Sebastian Riedel: mention chat.pl
23:12 good_news_everyon left #mojo
23:13 disputin joined #mojo
23:13 _dave_ What's the contrast on pubsub with, say using Mojo::EventEmitter or just a hash table of chat clients?
23:14 mattastrophe joined #mojo
23:14 Grinnz_ _dave_: its using an external DB, so it can communicate across preforked processes
23:14 Grinnz_ or even, across servers
23:14 _dave_ ah ha
23:24 KCL_ joined #mojo
23:35 sri haha, now i kinda want to add a button_for helper ;p that generates a <form...><input type="submit"...></form> block
23:36 sri for some reason i come across those in examples all the time now
23:37 sri %= button_for 'Edit post' => 'edit_post' => {id => $post->{id}}
23:40 sri hahaha, rails has it too and calls it button_to
23:42 sri it wraps the input element in a div though
23:42 Grinnz heh
23:43 sri padrino has it too
23:43 sri without the div ;p
23:44 sri padrino version is in fact exactly what i had in mind :o
23:50 sri not sure if it's worth 5 lines of code though :S

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