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

IRC log for #mojo, 2015-12-12

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

All times shown according to UTC.

Time Nick Message
00:05 harleypig That worked for the controller, but not for the model.  For the model, the app method can't be found.
00:05 harleypig the model is a Mojo::Base -base package
00:06 Grinnz it has no app, then, unless you tell it what the app is
00:06 Grinnz more likely, you'll just want to pass it the logger
00:08 harleypig So, in the controller method $self->mymodelmethod( $self->app->log, @parms ) ?
00:08 harleypig s/mymodel/mymodel->/
00:09 Grinnz or just store the logger in the object when you instantiate it
00:09 Grinnz has 'log';
00:12 marty joined #mojo
00:18 harleypig I remember reading about has, but I don't remember where and now I can't find it in the documentation. Also, when I add has 'log'; in my model doing $self->log( 'msg' ) doesn't cause an error, but nothing is printed to the logging screen.
00:19 Zoffix harleypig, has creates an attribute: https://metacpan.org/pod/Mojo::Base#has
00:20 harleypig Then I misunderstood what Grinnz  meant.
00:21 Grinnz you add that attribute to the model, then when you create the model with ->new(log => $app->log), then you can do $model->log->debug(...)
00:21 harleypig I've gone through the guides a couple of times, but I haven't seen anything that discusses logging, except in passing and not very well.
00:22 harleypig oic
00:26 harleypig All right. I see now. This works for any global attribute that doesn't come with Mojo::Base  ... it's beginning to make more sense to me. Thanks for putting up with my n00b questions.
00:34 asarch joined #mojo
00:41 jberger harleypig: make a helper that constructs those objects and passes in the necessary bound items
00:42 voldemortensen joined #mojo
00:43 harleypig I'm not sure what you mean. I know what a  helper is, but I'm not seeing how a helper  will work in this case.
00:45 harleypig Currently, my main module has $app->helper( mymethod => sub { state $mymethod = MyApp::Model::MyModel->new( log => $app->log )}); ...
00:46 harleypig You mean, make a helper that I can pass a list of models to? like $app->build_helpers( qw( MyApp::Model::MyModel MyApp::Model::MyModel2 )); ?
00:46 jberger state makes that a cached object, but otherwise yeah
00:46 marty joined #mojo
00:46 jberger I wouldn't call it build_helpers, I call it build_model
00:47 jberger but yeah basically
00:48 harleypig Hmmm ... so I could read my model directory and just auto add anything that was placed there, without having to modify the code. Nice.
00:48 jberger helper model => sub { my ($c, $class) = (shift, shift); "My::Model::$class"->new(app => $c->app, @_) });
00:49 jberger it'd have to be fancier to do things like loading the class etc, but that's a rough guide
00:49 jberger helpers are often the bridge between the controller and the model
00:52 harleypig Thank you. I'll experiment with that.
01:10 sri for the record, i strongly disagree with what jberger recommended there
01:10 sri "all you're doing there is write more controller code, and then call it a model to make yourself feel better about your bad abstraction choices"
01:11 sri that's what i said in #mojo-core about such code
01:13 sri there are some exceptions, like minion tasks that need to access the app, but if you're always keeping the app instance in your model instances, you've got bad code
01:16 harleypig I don't think I understand enough about mojo to understand you're objection. I'm looking at this as a way to avoid two things. First, having to have a long list of $app->help( modelname => sub { my $methodname = MyApp::Model::MyModels->new( log => $app->log )});, and second to allow myself and other developers to arbitrarily add new models withouth having to
01:16 harleypig remember to modify the base package. What am I missing?
01:18 sri why is your model logging at all?
01:18 sri how is it not the glue code?
01:19 sri model code throws errors, controller code logs them
01:21 harleypig I have a couple of models that are performing some complex tasks, I want to see what the result of various steps are, and I want all log messages to go to the same output.
01:22 harleypig I thought the controller is the glue code and the model does the heavy lfiting
01:22 sri thing is, you're turning models into controllers
01:23 sri models are supposed to be so generic that you can use them outside of a web app too
01:23 harleypig controllers are use to handle communication between the route and the model , or at least this is my understanding.
01:23 sri you're making them depend on a web app
01:24 sri of course you can do that, but it's bad style
01:24 harleypig I'm  not outputting anything to a web page, I'm outputting a log message.
01:24 harleypig ... I thought I was making the model depend on having some kind of a log method in the 'log' attribute.
01:24 sri my answer was for this recommendation http://irclog.perlgeek.de/mojo/2015-12-12#i_11702452
01:27 sri there's an example app that passes a Mojo::Pg instance to model classes https://github.com/kraih/mojo-pg/tree/master/examples/blog
01:27 harleypig Oh. I thought that was to be placed in the main app package ( lib/MyApp.pm::startup ) ... that's what I'm trying to do with what he suggested anyway. Though, jbergers code doesn't seem to do quite qhat I want.
01:28 harleypig This one? https://github.com/kraih/mojo-pg/blob/master/examples/blog/lib/Blog.pm#L16
01:28 sri yes
01:29 harleypig Yeah, that's what I based my current setup on, which is http://irclog.perlgeek.de/mojo/2015-12-12#i_11702442
01:30 mattp sri: how do you recommend config sharing to model?
01:32 mattp im confused by 'your model shouldnt log'
01:33 sri mattp: https://github.com/kraih/mojo-pg/blob/master/examples/blog/lib/Blog.pm#L15-L17
01:33 sri it's right there
01:33 mattp fair thanks
01:33 harleypig I think what jberger was recommending wasn't quite what I was wanting and sri thought I was doing what jberger recommended.
01:34 harleypig But I'm not positive.
01:34 sri harleypig: i still don't think a model should be logging though
01:34 sri if there's many complicated steps, perhaps those should be smaller methods called by the controller or a helper, which then does the logging
01:35 sri (i do consider helpers to be controler code)
01:35 sri +l
01:37 sri note that this is just my opinion, you can argue about design pattern purity all day
01:38 harleypig hmmm... so ... if I have a route that looks like POST /vm, which creates a new virtual machine in a cloud, which involves querying a db, cloning a git repo, sending multiple commands to a cloud interface and a few other steps; the controller should be calling the various methods instead of the model?
01:39 sri funny thing, rails sidesteps the logging in model question by having a global singleton logger :)
01:40 harleypig e.g., the controller should have $self->vm->query_db; handle logging and errors; $self->vm->clone_repo; handle logging and errors;  and so on?
01:40 harleypig I hate rails.
01:40 sri harleypig: that does look like something i would put in a helper, yea
01:41 harleypig I'm not trying to be contentious, I'm trying to make sure I'm on the same page as you, as far as understanding goes.
01:43 harleypig It seems to me that the model would depend on the controller for accomplishing it's task instead of being self-contained.
01:45 harleypig I see  your point though ... instead of having a controlling method in the model, it's in the controller package.
01:46 harleypig I need to think about it.
01:50 sri i think there are two camps here, a) thinks that models are only for sharing code between multiple controllers, and b) thinks that models should be sharable by multiple scripts
01:51 pink_mist are there any recommended articles about these issues? would like to read up on it more
01:51 sri by having a logger attribute in your model, you're putting a requirement on any host script to have logging too
01:56 sri pink_mist: not that i'm aware
01:56 pink_mist dang, ok ... guess I'll see if I can poke Su-Shee in the morning, she might know some useful article .. she tends to at least =)
01:57 chrisco1982 joined #mojo
01:57 sri guess it should be mentioned too that mojolicious templates are very impure too
01:58 sri traditionally the view talks to the model, but we allow controller access too
01:59 sri bottom line, you only have opinions here, no facts
02:00 pink_mist well sure, it's all opinions =)
02:20 voldemortensen joined #mojo
02:32 crazybigdan joined #mojo
02:32 crazybigdan So in a template, I want to source a js file
02:33 crazybigdan a la <script src="asdf.js"></script>
02:33 crazybigdan how do I do this?
02:35 pink_mist https://metacpan.org/pod/Mojolicious::Plugin::TagHelpers#javascript
02:46 jberger I will concede that I'm possibly in the wrong
02:47 jberger and yet in practice there are so many places in which having access to the app can be useful
02:47 jberger if for no other reason than configuration
02:47 crazybigdan Is there a folder that mojo checks in? such as "/script/asdf.js"?
02:47 jberger crazybigdan: http://mojolicio.us/perldoc/Mojolicious/Guides/Tutorial#Static-files
02:48 crazybigdan because I've add "%= javascript '/asdf.js'" to the bottom of my template and morbo is unable to find it
02:50 pink_mist well where did you place the *file*?
02:50 PryMar56 joined #mojo
02:50 crazybigdan Got it.
02:52 crazybigdan It was both an issue of not having the script file in the right place, and then some wonky permissions stuff
02:53 crazybigdan But thanks guys for the help; +1 for prompt responses at this hour.
02:53 pink_mist only because it's a weekend tomorrow :P
02:53 crazybigdan ha, living it up on friday night, I see :)
03:33 noganex_ joined #mojo
04:10 disputin joined #mojo
05:02 kaare joined #mojo
07:07 meshl joined #mojo
08:27 Vandal joined #mojo
08:29 sue joined #mojo
08:31 ladnaV joined #mojo
08:42 Vandal joined #mojo
08:45 trone joined #mojo
09:35 dod joined #mojo
09:40 dod joined #mojo
09:47 aitap joined #mojo
09:55 aitap Hi! I'd like to set my app->secret from the conffile and use Mojolicious::Plugin::Config for it. (Am I doing it wrong? I had used Config::Tiny before, but I now need a place to configure Hypnotoad outside my Lite application file.) So I do my $cnf = plugin Config => { default => { secret => Session::Token->... } }; and then app->secrets([$cnf->secret]);, but the warning about changing secret passphrase is fired when I'm loading my config, befo
09:55 aitap re I'm able to set the secrets. Is there a way to read my secret from a plugin 'Config' and not fire a warning?
09:56 aitap The code is currently at https://github.com/aitap/nanowiki/blob/plugin_config/nanowiki.pl#L79 if I was not sufficiently clear
10:05 aitap I could do somthing like app->config(secret => Session::Token(...), ..., %{my $cnf = do app->conffile});, but that sounds like rewriting the plugin.
10:12 henq joined #mojo
10:31 aitap Looking at channel history, others either don't get the warning, have found a way to disable it which I can't see or just ignore it: http://irclog.perlgeek.de/mojo/2015-04-10#i_10424305 https://github.com/XTaTIK/XTaTIK/blob/master/lib/XTaTIK.pm#L29
10:37 sh4 joined #mojo
10:37 meshl joined #mojo
10:49 sugar joined #mojo
10:53 fiyorin joined #mojo
12:15 flamey joined #mojo
12:16 flamey hi guys! maybe someone can help me out with this issue? http://stackoverflow.com/questions/34234451/wwwmechanizephantomjs-code-in-mojolicious-lite-script-doesnt-work-when-runn
12:16 flamey I feel like I'm doing something wrong on Mojolicious side
12:40 fiyorin joined #mojo
13:21 jabberwok joined #mojo
13:39 jberger flamey: are you running a selenium server somewhere?
13:40 jberger Also, do you need phantom for this?
13:40 pink_mist also, how about Mojo::Phantom (jberger, you gotta pimp it yourself too! :P)
13:40 jberger (Meaning are are trying to scrape or do you need to execute javascript or take screenshots? )
13:41 jberger pink_mist: we'll get there, it depends on needs
14:44 crab joined #mojo
14:45 upasana joined #mojo
14:46 PryMar56 joined #mojo
14:47 upasana_ joined #mojo
15:16 aitap I found the cause of the problem. It's the "conffile" helper I wrote and used: the first time it is run something inside Mojo tries to access secrets which I', about to load. I need to store a value somewhere inside a ::Lite application to use it from a command later. Are there cleaner ways to do it?
15:29 pink_mist aitap: have you checked the Mojo::Pg blog example? conf file like this: https://github.com/kraih/mojo-pg/blob/master/examples/blog/blog.conf and loading the secrets from it like this: https://github.com/kraih/mojo-pg/blob/master/examples/blog/lib/Blog.pm#L11-L12
15:30 pink_mist in Mojolicious::Lite that would just be a simple "plugin 'Config'; app->secrets(app->config->{secrets})
15:31 pink_mist err, this rather: in Mojolicious::Lite that would just be a simple "plugin 'Config'; app->secrets(app->config('secrets'))"
15:32 aitap pink_mist, I did, thank you. The problem is that I heed to pass the name of config file from my main Lite app to a command which lives in App::NanoWiki::admincmd namespace. I tried creating a helper 'conffile' (and thus using $self->app->conffile), but using a helper before setting secrets fires a warning.
15:33 pink_mist I don't understand why you need that, but ok
15:34 aitap I'd like a command to write a config file with default settings. Is there a way to design it in a cleaner way?
15:35 pink_mist ship a default config with your app?
15:39 aitap And leave secrets => [...] present but commented out by default? I like the idea, thanks. Though version control would start complaining if I implement it, so I'll keep looking for other ideas, too.
15:41 dod joined #mojo
15:45 asarch joined #mojo
15:56 aitap Turns out, there is a clean way: app->attr(conffile => $ENV{NANOWIKI_CONFIG} // "nanowiki.cnf"); in Lite app and $self->app->conffile in ::command
16:15 sh4 joined #mojo
16:20 sugar joined #mojo
16:30 good_news_everyon joined #mojo
16:30 good_news_everyon [mojo] kraih pushed 1 new commit to master: http://git.io/v0s16
16:30 good_news_everyon mojo/master 84a856c Sebastian Riedel: fix a few form generation bugs in Mojo::UserAgent::Transactor (closes #884)
16:30 good_news_everyon left #mojo
16:39 voldemortensen joined #mojo
17:21 disputin joined #mojo
17:38 asarch joined #mojo
17:48 voldemortensen joined #mojo
18:03 bjoernfan joined #mojo
18:45 jberger here's an odd one
18:45 jberger I have a websocket library that passes a websocket subprotocol
18:46 jberger I need to reply somehow to acknowledge it because chrome is giving me errors
18:46 jberger problem is exactly this as I confirmed by editing the library http://stackoverflow.com/questions/34198566/websocket-error-during-websocket-handshake-sent-non-empty-sec-websocket-proto
18:47 jberger but users will have the unpatched library, so I would like to figure out how to acknoledge it in the server
18:53 sri few weeks ago i wanted to add subprotocol negotiation, but nobody was interested ;p
18:54 henq joined #mojo
18:55 meshl joined #mojo
18:55 sri now i guess it's one more thing that won't happen before the refactoring
18:59 * sri prolly would have implemented it with something like $tx->with_protocols('foo', 'bar') and $tx->selected_protcol or so
18:59 jberger sri: I don't remember that
18:59 jberger can I hack it with the upgrade event?
19:07 sri https://github.com/kraih/mojo/issues/886
19:08 jberger so there is no api, but can it be hacked in the short term?
19:09 jberger I can't even get the upgrade event to fire
19:09 sri dunno
19:09 sri i only know how to do it right
19:11 sri think i even had a patch already
19:11 kafkaesque joined #mojo
19:14 jberger doh, the hook is after_build_tx not build_tx
19:15 jberger and yes, with the hook I can attach the upgrade event
19:15 jberger and in the upgrade event I can add the header
19:15 jberger but yes, this looks like a thing we should deal with
19:18 jberger I think chrome changed the way it handles subprotocol negotiation
19:18 sri so much depends on the refactoring :(
19:18 jberger I could still connect with firefox
19:19 jberger and the library only requests one subprotocol, but chrome wouldn't let me continue without acknowledging that one
19:19 jberger while firefox didn't care
19:19 jberger I'm 90% sure this code used to work in chrome
19:20 jberger yeah
19:20 jberger I'd like to get to the refactor
19:20 jberger I think I have a little time today (in a few hours) and maybe even a chuck of tomorrow
19:25 sri we've not heard from crab in two weeks i think
19:25 sri marcus, tempire: any of you got some time to hack on the refactoring?
19:53 sri *tumbleweed*
19:57 HtbaaPi joined #mojo
20:19 flamey joined #mojo
20:22 jwang joined #mojo
20:29 flamey continuing about my issue with PhanomJS: http://stackoverflow.com/questions/34234451/wwwmechanizephantomjs-code-in-mojolicious-lite-script-doesnt-work-when-runn
20:30 flamey I need to both run JS functions, get return from them, and also check DOM elements' values
20:32 flamey I looked at Mojo-Phanom, but couldn't understand how to use it for all this
20:34 flamey I'm not starting Selenium server anywhere (should I?), but the script works in foregorund mode. I figured if the problem was something not running, it shouldn't run at all
20:47 jberger flamey: I see the error coming out of the selenium driver
20:47 jberger I wonder if its trying to DTRT by checking whether the process is daemonized or something
20:47 jberger (and failing in this case)
20:48 jberger I don't think Mojo has much to do with it TBH
20:48 berov joined #mojo
20:52 flamey jberger, thanks for looking at it
20:53 jberger Mojo::Phantom is definitely geared towards testing, but it SHOULD be reusable
20:53 jberger then again, I would assume that WWW::Mechanise::PhantomJS probably is geared towards testing too
21:04 jberger sri: so I'm looking at taking the hash and turning it into a class
21:05 jberger what members should it have?
21:05 jberger certainly nb (is_nonblocking)
21:05 jberger and tx
21:06 jberger by for say the callback, that could probably just be an event that gets emitted?
21:25 jberger hmmmm, briefly I was considering whether or not to have the loop instance included rather than nb, however it seems that there are connection queues too?
21:40 sri yes, for keep-alive connections
21:41 sri in between transactions they go into queues
21:42 jberger so in that case, should I keep the Channel object or some lesser property?
21:43 jberger it feels like the nb property isn't really a property of the channel but how the user agent is using it
21:43 jberger the loop on the other hand is a property of the channel
21:44 jberger hmmm, UserAgent could determine whether its a blocking or nonblocking channel by if the channel's loop is the singleton
21:44 jberger :o
21:52 sri correct
22:05 jberger I have to keep reading and rereading to grok what should be channel methods (connect-ish) and which should be useragent (proxy?)
22:06 sri it's not very complicated
22:06 jberger when you know what's going on ;-P
22:06 sri where $self->{connections} gets accessed you try to move as much stuff as possible into methods
22:08 jberger what should I call the tcp id?
22:08 sri ideally including a $tx->client_* call
22:08 sri what do you need the id for?
22:08 jberger to say remove it from the loop
22:08 sri shouldn't that part be in the user agent?
22:09 jberger the channel object wouldn't know how to close itself?
22:09 sri i think the channel doesn't have to know... aside from $tx->connection
22:10 sri i guess you do need to know how Mojo::UserAgent works though, at least the basics
22:10 jberger that's what I'm absorbing now
22:10 sri best follow the lifecycle of a transaction once
22:11 jberger I almost never use a proxy either
22:11 sri from _start, over _connect, _read, _write to _finish
22:11 sri proxy shouldn't be so important
22:11 jberger all the _connect ish methods are what I'm reading now
22:12 sri it's basically just a CONNECT request on the connection before the real request
22:12 sri we just sneak in a transaction before the real transaction
22:12 jberger yeah, that's what I'm seeing
22:12 jberger and it fires off the next one with _start again
22:12 sri one small tricky thing, we steal the handle from the connection
22:13 sri and make a new connection with the handle, that allows the connection to be upgraded with TLS
22:13 sri tcp connection > CONNECT request > TLS upgrade > real request
22:14 sri but i think you don't have to do much in that code
22:15 sri SOCKS proxy stuff is transparent btw. and you don't have to worry at all
22:15 sri _connect_proxy is just for CONNECT
22:20 sri not sure if this is of interest... so feel free to ignore the following... there are three types of proxies we support, 1) SOCKS5, which is a binary protocol, and handled completely by Mojo::IOLoop::Client, 2) CONNECT, which establishes a connection with a special http request before the real request, handled by Mojo::UserAgent, and 3) plain old http proxies, where an absolute url is put into the start-line of the request, handled by Mojo
22:21 jberger maybe that was cut off?
22:21 jberger handled by Mojo ...
22:21 jberger I'm assuming that is Mojo::Message::
22:21 sri oh, yes it was, irssi showed me the full message :S
22:22 sri Mojo::Message::Request
22:22 sri that was the end
22:22 jberger ok
22:22 jberger I'll let this bake in the old noggin
22:23 jberger I'm about out of time for the evening, my wife is playing in a christmas concert tonight
22:23 sri sometimes i want to move the CONNECT stuff to Mojo::IOLoop::Client too, but the CONNECT request is real HTTP... with all the side effects to handle
22:24 sri have fun
22:24 sri really too bad it's become so hard to find volunteers
22:25 jberger I just need to get something started
22:25 jberger once we have something we can iterate on it will get easier
22:25 jberger just remember, its hard to find volunteers because this is the tough stuff
22:26 jberger much easier for ... other frameworks ... to find them, given their needs :-P
22:41 chansen sri: Moving CONNECT to Mojo::IOLoop::Client seems wrong, SOCKS operates at a lower level so it belongs in that package, but CONNECT is HTTP
22:45 sri chansen: yea
22:47 sri jberger: hope so
22:54 marcus I don't have a lot of time or interest in this refactor :-/ Sorry.
22:55 chansen marcus: your slacker ;oP
22:55 marcus chansen: slacker4you
22:56 sri quite the slacker, last commit by marcus was during mojoconf 2014 :o
23:00 marcus I promise to commit again at the next mojoconf.
23:12 nnutter joined #mojo
23:25 jabberwok1 joined #mojo
23:46 jabberwok1 left #mojo
23:49 voldemortensen joined #mojo
23:51 nnutter joined #mojo
23:57 voldemortensen1 joined #mojo

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