From sean at blanton.com Mon May 2 10:43:24 2011 From: sean at blanton.com (Sean Blanton) Date: Mon, 2 May 2011 12:43:24 -0500 Subject: [Chicago-talk] undef and Moose types In-Reply-To: <87ei4kxpua.fsf@snowball2.jrock.us> References: <201104290937.39913.andrew@cleverdomain.org> <87ei4kxpua.fsf@snowball2.jrock.us> Message-ID: Awesome, thanks for the detailed feedback. > This means you want dependency injection. Classes should *not* know how > to build things that they have; that's the job for some other part of > the program. Time to review my OO patterns! Bread::Board is a Moose-based module for dependency injection. ... I'm going to start using it. Regards, Sean On Sat, Apr 30, 2011 at 12:36 AM, Jonathan Rockway wrote: > * On Fri, Apr 29 2011, Sean Blanton wrote: > > Yeah, the 'Maybe' works great, and thanks for pointing me to the doc. > > > > My ssh_builder looks like your safe_ssh, not sure what you meant. I > > have one &ssh_builder for all (86!) classes. If a new class wants an > > ssh connection, it consumes the 'SSH' role with the ssh attribute > > populated by &ssh_builder. > > > Bread::Board is a Moose-based module for dependency injection. You can > write something like this: > > use Bread::Board; > my $c = container 'MyApp' as { > service 'ssh' => ( > class => 'Net::SSH', > lifecycle => 'Singleton', # if you want the same > # instance each time > ); > > service 'LogInAndDeleteEverything' => ( > class => 'MyApp::Action::LogInAndDeleteEverything', > dependencies => [ depends_on('ssh') ], > ); > }; > > my $action = $c->resolve( service => 'LogInAndDeleteEverything' ); > $action->execute; # everything is deleted > > Your MyApp::Action::LogInAndDeleteEverything would look something like: > > package MyApp::Action::LogInAndDeleteEverything; > use Moose; > > has 'ssh' => ( > is => 'ro', > isa => 'Net::SSH', > required => 1, > ); > > sub execute { ... } > > Bread::Board also has support for type mapping, so theoretically there > won't be much boilerplate even if you have 86 classes that all need the > 'ssh' service. I haven't used this feature much, however. > > In addition to class injection, there is also block injection, where you > can use a coderef to build the instance. Sometimes convenient. > > It's also worth noting that services can have parameters and that you > can pass in args during "resolve", so if your code looked something > like: > > has 'ssh' => ( ... as above ... ); > > has 'chdir_to' => ( ... ); > > Your service could be changed to: > > service 'LogInAndDeleteEverything' => ( # remind me never to use such > # a long name for an example! > class => 'MyApp::Action::LogInAndDeleteEverything', > dependencies => [ depends_on('ssh') ], > parameters => { chdir_to => { default => '/' } }, > ); > > Then, if you want to delete /etc, you would say: > > my $action = $c->resolve( > service => 'LogInAndDeleteEverything', > parameters => { chdir_to => '/etc' }, > ); > $action->execute; # BAI. > > Anyway, Bread::Board is pretty simple and easy to hack on, so it should > be possible to do what you want without making a mess. > > One more thing: you can make diagrams of your services and your > dependencies: > > > https://github.com/jrockway/BreadBoard/commit/83de2f946b0af5a129146a085abfc95173ed0130 > > Finally, I used Bread::Board::Service as an example in the README here: > > https://github.com/jrockway/graphviz-hasa > > Pretty! > > -- > print just => another => perl => hacker => if $,=$" > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Mon May 9 14:14:55 2011 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Mon, 9 May 2011 14:14:55 -0700 (PDT) Subject: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request Message-ID: <383512.6656.qm@web120506.mail.ne1.yahoo.com> Hello, Using LWP::UserAgent through proxy to access (GET or HEAD) https page, a Perl script responsed with ''_msg' => 'Bad Request'," while it is okay for POSTing on the same https page (redirect link is returned from POST response). There is no issue to access the the pages through IE/Firefox. I googled around but could not find any solution. Could anyone shed some light on this issue? Thanks Tiger, -------------- next part -------------- An HTML attachment was scrubbed... URL: From andy at petdance.com Mon May 9 14:15:56 2011 From: andy at petdance.com (Andy Lester) Date: Mon, 9 May 2011 16:15:56 -0500 Subject: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request In-Reply-To: <383512.6656.qm@web120506.mail.ne1.yahoo.com> References: <383512.6656.qm@web120506.mail.ne1.yahoo.com> Message-ID: <0A67DEB9-0CA0-4769-A153-BA9E8E77BC55@petdance.com> On May 9, 2011, at 4:14 PM, tiger peng wrote: > Using LWP::UserAgent through proxy to access (GET or HEAD) https page, a Perl script responsed with ''_msg' => 'Bad Request'," while it is okay for POSTing on the same https page (redirect link is returned from POST response). There is no issue to access the the pages through IE/Firefox. I googled around but could not find any solution. We need to see actual code in addition to your English summary. xoa -- Andy Lester => andy at petdance.com => www.techworklove.com => AIM:petdance -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Tue May 10 06:17:01 2011 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Tue, 10 May 2011 06:17:01 -0700 (PDT) Subject: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request In-Reply-To: <0A67DEB9-0CA0-4769-A153-BA9E8E77BC55@petdance.com> References: <383512.6656.qm@web120506.mail.ne1.yahoo.com> <0A67DEB9-0CA0-4769-A153-BA9E8E77BC55@petdance.com> Message-ID: <264823.47575.qm@web120520.mail.ne1.yahoo.com> Below is simplified code: #!/usr/bin/perl -w use strict; use LWP::UserAgent; use Data::Dumper; my $ua=LWP::UserAgent->new(); $ua->proxy(['https', 'http'] => 'http://corppac.myclient.com/accelerated_pac_base.pac'); my $response = $ua->get('https://login.yahoo.com/config/login_verify2?&.src=ym'); #my $response = $ua->get('http://www.yahoo.com'); print Dumper $response; No problem to access http://www.yahoo.com, but for access Yahoo login page With proxy, it compain: '_msg' => 'Bad Request', Without set proxy, it complain: '_msg' => 'Protocol scheme \'https\' is not supported (Crypt::SSLeay not installed)', ________________________________ From: Andy Lester To: Chicago.pm chatter Sent: Mon, May 9, 2011 4:15:56 PM Subject:Re: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request On May 9, 2011, at 4:14 PM, tiger peng wrote: Using LWP::UserAgent through proxy to access (GET or HEAD) https page, a Perl script responsed with ''_msg' => 'Bad Request'," while it is okay for POSTing on the same https page (redirect link is returned from POST response). There is no issue to access the the pages through IE/Firefox. I googled around but could not find any solution. We need to see actual code in addition to your English summary. xoa -- Andy Lester => andy at petdance.com => www.techworklove.com => AIM:petdance -------------- next part -------------- An HTML attachment was scrubbed... URL: From lee at laylward.com Tue May 10 07:57:44 2011 From: lee at laylward.com (Lee Aylward) Date: Tue, 10 May 2011 09:57:44 -0500 Subject: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request In-Reply-To: <264823.47575.qm@web120520.mail.ne1.yahoo.com> References: <383512.6656.qm@web120506.mail.ne1.yahoo.com> <0A67DEB9-0CA0-4769-A153-BA9E8E77BC55@petdance.com> <264823.47575.qm@web120520.mail.ne1.yahoo.com> Message-ID: <20110510095744.7b5afa05@hactar.servercentral.net> On Tue, 10 May 2011 06:17:01 -0700 (PDT) tiger peng wrote: > ... > > No problem to access http://www.yahoo.com, but for access Yahoo login > page With proxy, it compain: '_msg' => 'Bad Request', > Without set proxy, it complain: '_msg' => 'Protocol scheme \'https\' > is not supported (Crypt::SSLeay not installed)', > Well that error seems pretty clear, install Crypt::SSLeay. You may also want to look at your LWP version since there were some large changes in the latest major release (6.) If you have version 6+ I think you'll need to install LWP::Protocol::https to get https support. Good luck, -- Lee Aylward From sean at blanton.com Thu May 12 09:08:44 2011 From: sean at blanton.com (Sean Blanton) Date: Thu, 12 May 2011 11:08:44 -0500 Subject: [Chicago-talk] undef and Moose types In-Reply-To: References: <201104290937.39913.andrew@cleverdomain.org> <87ei4kxpua.fsf@snowball2.jrock.us> Message-ID: > > This means you want dependency injection. Classes should *not* know how >> to build things that they have; that's the job for some other part of >> the program. > > ... > Bread::Board is a Moose-based module for dependency injection. > > ... > > > It took some experimenting, but I've got something using Bread::Board that is way better than I had and still meets my goals of maximizing reuse and minimizing boiler plate. Since most of my classes use the same resources, I have one app container class that has app, log, db and ssh services defined. This container is sub-classed from Bread::Board::Container a la http://search.cpan.org/~stevan/Bread-Board-0.18/lib/Bread/Board/Manual/Concepts/Advanced.pod#Subclassing The container uses a variable for the class name, and I pass that name to the container class constructor and it creates all the resources and returns an instance of the class I want. This gives me the reuse so I don't have to create the same container for different application classes. I'll probably have a few "standard" containers. The dependency management between resources is divine. It's giving me the ability to make cleaner, hierarchical services with more finely grained encapsulation. I had been using Moose::Role's 'with' and 'require' which provided primitive forms of encapsulation and dependency management, but the shortcomings are now especially clear. It's kind of hard to show a complete example in an email, but here's how to get the app and run it, and then the container class from a working example. Feedback always appreciated. ========================== use app_cntnr; my $c = app_cntnr->new( name => 'app_cntnr', class => 'app', ); my $app = $c->resolve( service => 'application' ); $app->do_something(); ========================== package app_cntnr; use Moose; use Bread::Board; extends 'Bread::Board::Container'; has 'class' => ( is => 'ro', isa => 'Str', required => 1, ); sub BUILD { my $s = shift; container $s => as { service 'log_svc' => ( class => 'log_svc', lifecycle => 'Singleton', ); service 'db_svc' => ( #-- svc for the raw DBI database handle class => 'db_svc', dependencies => { log_svc => depends_on('log_svc'), } ); service 'exec_db_svc' => ( #-- interacts with the database class => 'exec_db_svc', dependencies => { log_svc => depends_on('log_svc'), db_svc => depends_on('db_svc'), } ); service 'ssh_svc' => ( #-- svc for the raw Net::SSH2 connection class => 'ssh_svc', dependencies => { log_svc => depends_on('log_svc'), } ); service 'exec_ssh_svc' => ( #-- Interacts with remote OS over ssh class => 'exec_ssh_svc', dependencies => { log_svc => depends_on('log_svc'), ssh_svc => depends_on('ssh_svc'), } ); service 'application' => ( class => $s->class, dependencies => { log_svc => depends_on('log_svc'), exec_db => depends_on('exec_db_svc'), exec_ssh => depends_on('exec_ssh_svc'), } ); }; } no Moose; 1; Regards, Sean On Mon, May 2, 2011 at 12:43 PM, Sean Blanton wrote: > Awesome, thanks for the detailed feedback. > > >> This means you want dependency injection. Classes should *not* know how >> to build things that they have; that's the job for some other part of >> the program. > > > Time to review my OO patterns! > > Bread::Board is a Moose-based module for dependency injection. > > ... > > > I'm going to start using it. > > Regards, > Sean > > On Sat, Apr 30, 2011 at 12:36 AM, Jonathan Rockway < > jon-chicagotalk at jrock.us> wrote: > >> * On Fri, Apr 29 2011, Sean Blanton wrote: >> > Yeah, the 'Maybe' works great, and thanks for pointing me to the doc. >> > >> > My ssh_builder looks like your safe_ssh, not sure what you meant. I >> > have one &ssh_builder for all (86!) classes. If a new class wants an >> > ssh connection, it consumes the 'SSH' role with the ssh attribute >> > populated by &ssh_builder. >> >> >> Bread::Board is a Moose-based module for dependency injection. You can >> write something like this: >> >> use Bread::Board; >> my $c = container 'MyApp' as { >> service 'ssh' => ( >> class => 'Net::SSH', >> lifecycle => 'Singleton', # if you want the same >> # instance each time >> ); >> >> service 'LogInAndDeleteEverything' => ( >> class => 'MyApp::Action::LogInAndDeleteEverything', >> dependencies => [ depends_on('ssh') ], >> ); >> }; >> >> my $action = $c->resolve( service => 'LogInAndDeleteEverything' ); >> $action->execute; # everything is deleted >> >> Your MyApp::Action::LogInAndDeleteEverything would look something like: >> >> package MyApp::Action::LogInAndDeleteEverything; >> use Moose; >> >> has 'ssh' => ( >> is => 'ro', >> isa => 'Net::SSH', >> required => 1, >> ); >> >> sub execute { ... } >> >> Bread::Board also has support for type mapping, so theoretically there >> won't be much boilerplate even if you have 86 classes that all need the >> 'ssh' service. I haven't used this feature much, however. >> >> In addition to class injection, there is also block injection, where you >> can use a coderef to build the instance. Sometimes convenient. >> >> It's also worth noting that services can have parameters and that you >> can pass in args during "resolve", so if your code looked something >> like: >> >> has 'ssh' => ( ... as above ... ); >> >> has 'chdir_to' => ( ... ); >> >> Your service could be changed to: >> >> service 'LogInAndDeleteEverything' => ( # remind me never to use such >> # a long name for an example! >> class => 'MyApp::Action::LogInAndDeleteEverything', >> dependencies => [ depends_on('ssh') ], >> parameters => { chdir_to => { default => '/' } }, >> ); >> >> Then, if you want to delete /etc, you would say: >> >> my $action = $c->resolve( >> service => 'LogInAndDeleteEverything', >> parameters => { chdir_to => '/etc' }, >> ); >> $action->execute; # BAI. >> >> Anyway, Bread::Board is pretty simple and easy to hack on, so it should >> be possible to do what you want without making a mess. >> >> One more thing: you can make diagrams of your services and your >> dependencies: >> >> >> https://github.com/jrockway/BreadBoard/commit/83de2f946b0af5a129146a085abfc95173ed0130 >> >> Finally, I used Bread::Board::Service as an example in the README here: >> >> https://github.com/jrockway/graphviz-hasa >> >> Pretty! >> >> -- >> print just => another => perl => hacker => if $,=$" >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Fri May 13 06:36:38 2011 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Fri, 13 May 2011 06:36:38 -0700 (PDT) Subject: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request In-Reply-To: <20110510095744.7b5afa05@hactar.servercentral.net> References: <383512.6656.qm@web120506.mail.ne1.yahoo.com> <0A67DEB9-0CA0-4769-A153-BA9E8E77BC55@petdance.com> <264823.47575.qm@web120520.mail.ne1.yahoo.com> <20110510095744.7b5afa05@hactar.servercentral.net> Message-ID: <185701.42511.qm@web120506.mail.ne1.yahoo.com> All, Unable to install perl module on client's Linux server, I test the script with newly installed strawberry Perl on laptop (Installation of LWP::Protocol::https was failed) http/https connection (no proxy) from home okay. https connection behind the firewall (with proxy): "Bad Request" (tried $ua->agent('Mozilla/5.0'). No effect). Any thought? Thanks, ________________________________ From: Lee Aylward To: chicago-talk at pm.org Sent: Tue, May 10, 2011 9:57:44 AM Subject:Re: [Chicago-talk] LWP::UserAgent->get('https://....") invalid_request On Tue, 10 May 2011 06:17:01 -0700 (PDT) tiger peng wrote: > ... > > No problem to access http://www.yahoo.com, but for access Yahoo login > page With proxy, it compain: '_msg' => 'Bad Request', > Without set proxy, it complain: '_msg' => 'Protocol scheme \'https\' > is not supported (Crypt::SSLeay not installed)', > Well that error seems pretty clear, install Crypt::SSLeay. You may also want to look at your LWP version since there were some large changes in the latest major release (6.) If you have version 6+ I think you'll need to install LWP::Protocol::https to get https support. Good luck, -- Lee Aylward _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Tue May 24 13:49:15 2011 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Tue, 24 May 2011 13:49:15 -0700 (PDT) Subject: [Chicago-talk] Use vi in perl Message-ID: <675891.60313.qm@web120504.mail.ne1.yahoo.com> Hello all, I am trying to use vi as a UI to edit/check dynamic created perl code segment. When user save and quite the vi, the script will check its syntax and force to open the file again if there are any compiling error. I'd like to have the error message show in the new opened vi interface but don't know how to do it. Is here any suggestion? Thanks, Below is the segment invoke vi and do the check? my $msg; do { if (defined $msg) { warn "$msg"; my $dummy = ; } system("/bin/vi", $tmpfile) == 0 or die $!; $msg = `/usr/bin/perl -c $tmpfile`; } while ($? != 0); -------------- next part -------------- An HTML attachment was scrubbed... URL: From merlyn at stonehenge.com Tue May 24 14:01:33 2011 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Tue, 24 May 2011 14:01:33 -0700 Subject: [Chicago-talk] Use vi in perl In-Reply-To: <675891.60313.qm@web120504.mail.ne1.yahoo.com> (tiger peng's message of "Tue, 24 May 2011 13:49:15 -0700 (PDT)") References: <675891.60313.qm@web120504.mail.ne1.yahoo.com> Message-ID: <86mxib24pe.fsf@red.stonehenge.com> >>>>> "tiger" == tiger peng writes: tiger> I am trying to use vi as a UI to edit/check dynamic created perl code segment. tiger> When user save and quite the vi, the script will check its syntax and force to tiger> open the file again if there are any compiling error. I'd like to have the error tiger> message show in the new opened vi interface but don't know how to do it. Is here tiger> any suggestion? tiger> Thanks, tiger> Below is the segment invoke vi and do the check? tiger> my $msg; tiger> do { tiger> if (defined $msg) { tiger> warn "$msg"; tiger> my $dummy = ; tiger> } tiger> system("/bin/vi", $tmpfile) == 0 or die $!; tiger> $msg = `/usr/bin/perl -c $tmpfile`; tiger> } while ($? != tiger> 0);_______________________________________________ Maybe something like (untested, but I usually get this right): LOOP: { system "vi", $tempfile and die "vi exited badly"; my $pid = open ERRS, "-|"; die "can't fork: $!" unless defined $pid; unless ($pid) { # child does: open STDERR, ">&STDOUT"; # merge stderr to stdout exec "perl", "-c", $tempfile; } my $errs; $errs .= $_ while ; close ERRS; if ($errs) { # we saw something wrong local *ARGV; # prepare for in-place edit @ARGV = ($tmpfile); while (<>) { print; ## insert error messages at end of data print "\n\n=for COMPILER_ERRORS\n\n$errs\n\n=cut\n\n" if eof; } redo LOOP; } } # done The first person to say "No, you should have used a lexical filehandle there" will get a free copy of my "Perl Second Best Practices" slide deck, subtitled "Why Damian's guidelines are just that... guidelines". -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion From jim at jimandkoka.com Tue May 24 14:07:49 2011 From: jim at jimandkoka.com (Jim Thomason) Date: Tue, 24 May 2011 17:07:49 -0400 Subject: [Chicago-talk] Use vi in perl In-Reply-To: <86mxib24pe.fsf@red.stonehenge.com> References: <675891.60313.qm@web120504.mail.ne1.yahoo.com> <86mxib24pe.fsf@red.stonehenge.com> Message-ID: > The first person to say "No, you should have used a lexical filehandle > there" will get a free copy of my "Perl Second Best Practices" slide > deck, subtitled "Why Damian's guidelines are just that... guidelines". Well then, is there a strong reason -not- to use a lexical filehandle (either in this case or generally)? Or are you just being curmudgeonly and I should get off your lawn? :-) -Jim.... From merlyn at stonehenge.com Tue May 24 15:40:31 2011 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Tue, 24 May 2011 15:40:31 -0700 Subject: [Chicago-talk] Use vi in perl In-Reply-To: (Jim Thomason's message of "Tue, 24 May 2011 17:07:49 -0400") References: <675891.60313.qm@web120504.mail.ne1.yahoo.com> <86mxib24pe.fsf@red.stonehenge.com> Message-ID: <86hb8j204g.fsf@red.stonehenge.com> >>>>> "Jim" == Jim Thomason writes: >> The first person to say "No, you should have used a lexical filehandle >> there" will get a free copy of my "Perl Second Best Practices" slide >> deck, subtitled "Why Damian's guidelines are just that... guidelines". Jim> Well then, is there a strong reason -not- to use a lexical filehandle Jim> (either in this case or generally)? Jim> Or are you just being curmudgeonly and I should get off your lawn? Jim> :-) I avoid lexical filehandles for 10-line scripts. I find the original classic package filehandles to be less noise. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion From robert at robertblackwell.com Tue May 24 17:18:05 2011 From: robert at robertblackwell.com (Robert Blackwell) Date: Tue, 24 May 2011 20:18:05 -0400 Subject: [Chicago-talk] Use vi in perl In-Reply-To: <675891.60313.qm@web120504.mail.ne1.yahoo.com> References: <675891.60313.qm@web120504.mail.ne1.yahoo.com> Message-ID: http://search.cpan.org/~rokr/Term-EditorEdit-0.0015/lib/Term/EditorEdit.pm has proved useful to me. Used with http://search.cpan.org/~rjbs/Test-Deep-0.108/lib/Test/Deep/NoTest.pm and http://search.cpan.org/~shlomif/Config-IniFiles-2.66/lib/Config/IniFiles.pm On May 24, 2011, at 4:49 PM, tiger peng wrote: > Hello all, > > I am trying to use vi as a UI to edit/check dynamic created perl code segment. When user save and quite the vi, the script will check its syntax and force to open the file again if there are any compiling error. I'd like to have the error message show in the new opened vi interface but don't know how to do it. Is here any suggestion? > > Thanks, > > Below is the segment invoke vi and do the check? > > my $msg; > do { > if (defined $msg) { > warn "$msg"; > my $dummy = ; > } > system("/bin/vi", $tmpfile) == 0 or die $!; > $msg = `/usr/bin/perl -c $tmpfile`; > } while ($? != 0); > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: