From dave at dave.org.uk Wed Apr 10 01:39:57 2013 From: dave at dave.org.uk (Dave Cross) Date: Wed, 10 Apr 2013 09:39:57 +0100 Subject: [Edinburgh-pm] brian d foy Message-ID: <20130410093957.2951224e6wqcqs7x@webmail.mag-sol.com> Hi, I was out with brian d foy last night and he mentioned that he was heading up to Edinburgh later in the week. I mentioned what a hospitable bunch the Edinburgh Perl Mongers were and he asked me to put him in touch with you. Which is what I'm doing here :) Cheers, Dave... From perl at minty.org Wed Apr 10 02:08:53 2013 From: perl at minty.org (Murray) Date: Wed, 10 Apr 2013 10:08:53 +0100 Subject: [Edinburgh-pm] brian d foy In-Reply-To: <20130410093957.2951224e6wqcqs7x@webmail.mag-sol.com> References: <20130410093957.2951224e6wqcqs7x@webmail.mag-sol.com> Message-ID: <20130410090852.GA6253@mooker.vm.bytemark.co.uk> On Wed, Apr 10, 2013 at 09:39:57AM +0100, Dave Cross wrote: > Which is what I'm doing here :) Brilliant :) Brian -- we're traditionally more a social group -- up for a beer? What day(s) suit? If you need any pointers around Edinburgh, just give us a shout. Murray. From perl at aaroncrane.co.uk Wed Apr 10 10:31:03 2013 From: perl at aaroncrane.co.uk (Aaron Crane) Date: Wed, 10 Apr 2013 18:31:03 +0100 Subject: [Edinburgh-pm] brian d foy In-Reply-To: <20130410090852.GA6253@mooker.vm.bytemark.co.uk> References: <20130410093957.2951224e6wqcqs7x@webmail.mag-sol.com> <20130410090852.GA6253@mooker.vm.bytemark.co.uk> Message-ID: Murray wrote: > Brian -- we're traditionally more a social group -- up for a beer? > > What day(s) suit? I'll definitely come along if I can make it, but I'm at the QA Hackathon this weekend. Hope we can sort out a date that works for everyone :-) -- Aaron Crane ** http://aaroncrane.co.uk/ From wim.vanderbauwhede at gmail.com Sat Apr 13 09:36:08 2013 From: wim.vanderbauwhede at gmail.com (Wim Vanderbauwhede) Date: Sat, 13 Apr 2013 17:36:08 +0100 Subject: [Edinburgh-pm] Perl code generator Message-ID: Hi folks, I told some of you at the last .pm that I wanted to write a code generator that converts a Perl script into source code in my GPIR language, simply by running the script. For example: use GPRM; use GPRM::DocFilter; my @dfs = map {new GPRM::DocFilter($_)} 1..8; my $df2 = new GPRM::DocFilter(9); { my @vals; for my $i (1..8) { push @vals, $dfs[$i-1]->score($i) } $df2->aggregate(@vals); } What this does is generate code that will score a document collection using 8 threads and aggregate the results. The score and aggregate methods are assumed to be provided by the DocFilter class. The 'use GPRM' does the heavy lifting: it reads the source in the GPRM.pm module, transforms it, and then uses exec() to call perl on the new code. The GPRM::DocFilter module does not exist, a stub is created to keep perl happy. What happens is that a call like $df2->aggregate() uses AUTOLOAD to generate the code in my GPIR language. The result is something like this: ; docfilter.yml (label L_1 (c1.DocFilter.DocFilter.score '1)) (label L_2 (c2.DocFilter.DocFilter.score '2)) (label L_3 (c3.DocFilter.DocFilter.score '3)) (label L_4 (c4.DocFilter.DocFilter.score '4)) (label L_5 (c5.DocFilter.DocFilter.score '5)) (label L_6 (c6.DocFilter.DocFilter.score '6)) (label L_7 (c7.DocFilter.DocFilter.score '7)) (label L_8 (c8.DocFilter.DocFilter.score '8)) (label L_9 (c0.Ctrl.Ctrl.begin )) (label L_10 (c9.DocFilter.DocFilter.aggregate L_1 L_2 L_3 L_4 L_5 L_6 L_7 L_8)) (label L_11 (c0.Ctrl.Ctrl.begin L_10)) This gets compiled into bytecode and runs on my GPRM VM. At the last .pm meeting, I got a number of interesting suggestions. In the end it turned out I had to do a lot more parsing and analysis for the transformations than I thought, so I ended up using PPI. It's not pretty but it works. You can find it on GitHub: https://github.com/wimvanderbauwhede/Perl-GPIR-Generator I created two modules, PPI::Visitors and PPI::Generators, which are general-purpose. The first provides a tree walker that you can provide with your own node transformations and context. The second provides a number of functions to generate PPI nodes and often-used compounds like method calls. The actual code transformations are in GPRM::Transformer The code generation is in GPRM I would really value some feedback on this. It's still buggy but I've uploaded it anyway. So if you can spare a moment, have a look. Thanks! Wim -------------- next part -------------- An HTML attachment was scrubbed... URL: From wim.vanderbauwhede at gmail.com Sun Apr 14 11:11:42 2013 From: wim.vanderbauwhede at gmail.com (Wim Vanderbauwhede) Date: Sun, 14 Apr 2013 19:11:42 +0100 Subject: [Edinburgh-pm] Perl code generator In-Reply-To: <20130413193603.GC6253@mooker.vm.bytemark.co.uk> References: <20130413193603.GC6253@mooker.vm.bytemark.co.uk> Message-ID: Hi Murray, Thanks a lot for the feedback. I apologise for not testing my stuff more thoroughly, I hadn't actually though people were going to run it, just look at it :-) On 13 April 2013 20:36, Murray wrote: > On Sat, Apr 13, 2013 at 05:36:08PM +0100, Wim Vanderbauwhede wrote: > > For example: > > > > use GPRM; > > use GPRM::DocFilter; > > > > my @dfs = map {new GPRM::DocFilter($_)} 1..8; > > my $df2 = new GPRM::DocFilter(9); > > > > { > > my @vals; > > for my $i (1..8) { > > push @vals, $dfs[$i-1]->score($i) > > } > > $df2->aggregate(@vals); > > } > > Ok -- so I'm not claiming to really grok all of the details, and I've only > had > a cursory glance, so forgive stupid / newbie mistakes ... but I always > find it > useful to get that feedback, even if it's probably not what you were really > hoping for here ;) > > Also, this is kinda brain dump, sorry :) > > --- > > So first I forked your repo -- gives me a place to play. > > https://github.com/minty/Perl-GPIR-Generator > > then > > git clone git at github.com:minty/Perl-GPIR-Generator.git > > cd Perl-GPIR-Generator > vi sample > > Then I set "sample" to be: > > #!/usr/bin/env perl > > use GPRM; > use GPRM::DocFilter; > > my @dfs = map { new GPRM::DocFilter($_) } 1..8; > my $df2 = new GPRM::DocFilter(9); > my $NTH = 8; > > { > my @vals; > for my $i (1..$NTH) { > push @vals, $dfs[$i-1]->score($i) > } > $df2->aggregate(@vals); > } > > ran it, and got: > > ? chmod u+x ./sample > ? ./sample > > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > ... > > I tried it with: > > ? perl ./sample > > but same result. > > I seem to get these littering the filesystem: > > # _PROC__PROC__PROC__PROC__PROC_sample > # _PROC__PROC__PROC__PROC_sample > # _PROC__PROC__PROC_sample > # _PROC__PROC_sample > # _PROC_sample > > Which makes me wonder if File::Temp, used with it's CLEANUP => 1 > constructor > arg might be relevant? > > Could be, will check it out > I had to Ctrl-C "sample" in both the above cases. > This should be fixed now. I made a mistake in how I check for the generated file name. > > fwiw, I'm using perlbrew: > > ? perl -v > This is perl 5, version 16, subversion 3 (v5.16.3) built for i686-linux > > ? cat /etc/lsb-release > DISTRIB_ID=Ubuntu > DISTRIB_RELEASE=12.04 > DISTRIB_CODENAME=precise > DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS" > > Running: > > ? perl transform_GPRM.pl > > Seems to work and produce plausible output. > > ? perl matmult.pl > Can't locate GPRM/MatrixOps.pm in @INC ... [snipped long @INC paths] > > I can't see GPRM/MatrixOps.pm in the git repo ... ? > I forgot a few lines in the script :-( Fixed now. GPRM/MatrixOps.pm is a generated stub, that's why it's not in the repo. > ? perl matops.pl > > produces: > > ------------ > ADD TO REG TABLE $GPRM::A > ------------ > ADD TO REG TABLE $GPRM::B > ------------ > ADD TO REG TABLE $GPRM::C > ------------ > ADD TO REG TABLE $GPRM::D > ------------ > $GPRM::A exists in REG TABLE > REG_READ <1>:<$GPRM::A> > ------------ > $GPRM::B exists in REG TABLE > REG_READ <2>:<$GPRM::B> > ------------ > ADD TO REG TABLE $GPRM::AB > ------------ > $GPRM::C exists in REG TABLE > REG_READ <3>:<$GPRM::C> > ------------ > $GPRM::D exists in REG TABLE > REG_READ <4>:<$GPRM::D> > ------------ > ADD TO REG TABLE $GPRM::CD > ------------ > $GPRM::AB exists in REG TABLE > REG_READ <5>:<$GPRM::AB> > ------------ > $GPRM::CD exists in REG TABLE > REG_READ <6>:<$GPRM::CD> > Name "GPRM::CD" used only once: possible typo at _PROC_matops.pl line 85. > Name "GPRM::C" used only once: possible typo at _PROC_matops.pl line 70. > Name "GPRM::A" used only once: possible typo at _PROC_matops.pl line 58. > Name "GPRM::B" used only once: possible typo at _PROC_matops.pl line 58. > Name "GPRM::D" used only once: possible typo at _PROC_matops.pl line 70. > Name "GPRM::AB" used only once: possible typo at _PROC_matops.pl line 85. > Can't locate object method "new" via package "Mat" (perhaps you forgot to > load "Mat"?) at _PROC_matops.pl line 40. > Another mistake in the script, fixed now. You'll still get the warnings, that is because my transformer is not yet complete. > > --- > > time for some dinner now -- I'll have a further play with > transform_GPRM.pl in > due course, as currently it is the only one that seems to really work for > me. > > feedback? make it easier to get a working demo, or unit tests. Test are, in > addition to all the testing things, my first port of call to run the code > in > anger, and start messing with it. They are often where I copy/paste from > to > start playing, as my assumption is they are worked-examples of how the > code is > intended to be used. > Correct. Only I did not actually test all the test cases in the repo ^_^; > > I realise that *might* be tricky in this case ... but ... well, feedback. > More > tests. Primarily, for a "worked example of the code in use" rather than > worrying about "comprehensive test coverage". > > So ... I tried to create a minimal test file -- no love :( > > ? cat t/01_basic.t > #!/usr/bin/env perl > > use FindBin; > use lib "$FindBin::Bin"; > > use common::sense; > use Test::More; > > use_ok 'GPRM'; > > done_testing(); > > murray at testing:~/github/Perl-GPIR-Generator? perl t/01_basic.t > Can't open perl script > "t/_PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC_01_basic.t": > File name too long > Same stupid bug again, should probably be OK now, though I don't know what the output of this test should be. > > --- > > fwiw: > > #!/usr/bin/env perl > > I use perlbrew [1], and this makes yer scripts "more portable" in such > environs. > > Don't know it, will check it out > use common::sense; > Ditto > > it works for me, and it's less boilerplate than: > > use strict; > use warnings; > use 5.10; > > plus, I concur with the general sentiment of the pod, even if frankly the > details are tl;dr for me. ymmv obviously :) > > [1] re: perlbrew ... fwiw, this is my baseline: > > curl -kL http://install.perlbrew.pl | bash > echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc > source ~/perl5/perlbrew/etc/bashrc > perlbrew install --switch stable > perlbrew install-cpanm > > Optionally, if you have multiple CPUS, with "-j 8" (or some other value > for 8) > added to the first "perlbrew install" line. Makes it silly fast to > install a > new Perl :) > > http://www.dagolden.com/index.php/1384/parallel-make-for-perlbrew/ > > Then I rely heavily on cpanm -- at least, for dev/play. Production is an > entirely different ball game. > How so? cpanm not good for production? > > ? cpanm common::sense > > etc. > Thanks a lot! Wim -- If it's pointless, what's the point? If there is a point to it, what's the point? (Tibor Fischer, "The Thought Gang") On 13 April 2013 20:36, Murray wrote: > On Sat, Apr 13, 2013 at 05:36:08PM +0100, Wim Vanderbauwhede wrote: > > For example: > > > > use GPRM; > > use GPRM::DocFilter; > > > > my @dfs = map {new GPRM::DocFilter($_)} 1..8; > > my $df2 = new GPRM::DocFilter(9); > > > > { > > my @vals; > > for my $i (1..8) { > > push @vals, $dfs[$i-1]->score($i) > > } > > $df2->aggregate(@vals); > > } > > Ok -- so I'm not claiming to really grok all of the details, and I've only > had > a cursory glance, so forgive stupid / newbie mistakes ... but I always > find it > useful to get that feedback, even if it's probably not what you were really > hoping for here ;) > > Also, this is kinda brain dump, sorry :) > > --- > > So first I forked your repo -- gives me a place to play. > > https://github.com/minty/Perl-GPIR-Generator > > then > > git clone git at github.com:minty/Perl-GPIR-Generator.git > > cd Perl-GPIR-Generator > vi sample > > Then I set "sample" to be: > > #!/usr/bin/env perl > > use GPRM; > use GPRM::DocFilter; > > my @dfs = map { new GPRM::DocFilter($_) } 1..8; > my $df2 = new GPRM::DocFilter(9); > my $NTH = 8; > > { > my @vals; > for my $i (1..$NTH) { > push @vals, $dfs[$i-1]->score($i) > } > $df2->aggregate(@vals); > } > > ran it, and got: > > ? chmod u+x ./sample > ? ./sample > > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > Deep recursion on subroutine "PPI::Visitors::visit_tree" at > PPI/Visitors.pm line 97. > ... > > I tried it with: > > ? perl ./sample > > but same result. > > I seem to get these littering the filesystem: > > # _PROC__PROC__PROC__PROC__PROC_sample > # _PROC__PROC__PROC__PROC_sample > # _PROC__PROC__PROC_sample > # _PROC__PROC_sample > # _PROC_sample > > Which makes me wonder if File::Temp, used with it's CLEANUP => 1 > constructor > arg might be relevant? > > I had to Ctrl-C "sample" in both the above cases. > > fwiw, I'm using perlbrew: > > ? perl -v > This is perl 5, version 16, subversion 3 (v5.16.3) built for i686-linux > > ? cat /etc/lsb-release > DISTRIB_ID=Ubuntu > DISTRIB_RELEASE=12.04 > DISTRIB_CODENAME=precise > DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS" > > Running: > > ? perl transform_GPRM.pl > > Seems to work and produce plausible output. > > ? perl matmult.pl > Can't locate GPRM/MatrixOps.pm in @INC ... [snipped long @INC paths] > > I can't see GPRM/MatrixOps.pm in the git repo ... ? > > ? perl matops.pl > > produces: > > ------------ > ADD TO REG TABLE $GPRM::A > ------------ > ADD TO REG TABLE $GPRM::B > ------------ > ADD TO REG TABLE $GPRM::C > ------------ > ADD TO REG TABLE $GPRM::D > ------------ > $GPRM::A exists in REG TABLE > REG_READ <1>:<$GPRM::A> > ------------ > $GPRM::B exists in REG TABLE > REG_READ <2>:<$GPRM::B> > ------------ > ADD TO REG TABLE $GPRM::AB > ------------ > $GPRM::C exists in REG TABLE > REG_READ <3>:<$GPRM::C> > ------------ > $GPRM::D exists in REG TABLE > REG_READ <4>:<$GPRM::D> > ------------ > ADD TO REG TABLE $GPRM::CD > ------------ > $GPRM::AB exists in REG TABLE > REG_READ <5>:<$GPRM::AB> > ------------ > $GPRM::CD exists in REG TABLE > REG_READ <6>:<$GPRM::CD> > Name "GPRM::CD" used only once: possible typo at _PROC_matops.pl line 85. > Name "GPRM::C" used only once: possible typo at _PROC_matops.pl line 70. > Name "GPRM::A" used only once: possible typo at _PROC_matops.pl line 58. > Name "GPRM::B" used only once: possible typo at _PROC_matops.pl line 58. > Name "GPRM::D" used only once: possible typo at _PROC_matops.pl line 70. > Name "GPRM::AB" used only once: possible typo at _PROC_matops.pl line 85. > Can't locate object method "new" via package "Mat" (perhaps you forgot to > load "Mat"?) at _PROC_matops.pl line 40. > > --- > > time for some dinner now -- I'll have a further play with > transform_GPRM.pl in > due course, as currently it is the only one that seems to really work for > me. > > feedback? make it easier to get a working demo, or unit tests. Test are, > in > addition to all the testing things, my first port of call to run the code > in > anger, and start messing with it. They are often where I copy/paste from > to > start playing, as my assumption is they are worked-examples of how the > code is > intended to be used. > > I realise that *might* be tricky in this case ... but ... well, feedback. > More > tests. Primarily, for a "worked example of the code in use" rather than > worrying about "comprehensive test coverage". > > So ... I tried to create a minimal test file -- no love :( > > ? cat t/01_basic.t > #!/usr/bin/env perl > > use FindBin; > use lib "$FindBin::Bin"; > > use common::sense; > use Test::More; > > use_ok 'GPRM'; > > done_testing(); > > murray at testing:~/github/Perl-GPIR-Generator? perl t/01_basic.t > Can't open perl script > "t/_PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC_01_basic.t": > File name too long > > --- > > fwiw: > > #!/usr/bin/env perl > > I use perlbrew [1], and this makes yer scripts "more portable" in such > environs. > > use common::sense; > > it works for me, and it's less boilerplate than: > > use strict; > use warnings; > use 5.10; > > plus, I concur with the general sentiment of the pod, even if frankly the > details are tl;dr for me. ymmv obviously :) > > [1] re: perlbrew ... fwiw, this is my baseline: > > curl -kL http://install.perlbrew.pl | bash > echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc > source ~/perl5/perlbrew/etc/bashrc > perlbrew install --switch stable > perlbrew install-cpanm > > Optionally, if you have multiple CPUS, with "-j 8" (or some other value > for 8) > added to the first "perlbrew install" line. Makes it silly fast to > install a > new Perl :) > > http://www.dagolden.com/index.php/1384/parallel-make-for-perlbrew/ > > Then I rely heavily on cpanm -- at least, for dev/play. Production is an > entirely different ball game. > > ? cpanm common::sense > > etc. > -- If it's pointless, what's the point? If there is a point to it, what's the point? (Tibor Fischer, "The Thought Gang") -------------- next part -------------- An HTML attachment was scrubbed... URL: From perl at aaroncrane.co.uk Mon Apr 15 06:59:01 2013 From: perl at aaroncrane.co.uk (Aaron Crane) Date: Mon, 15 Apr 2013 14:59:01 +0100 Subject: [Edinburgh-pm] EMERGENCY: Schwern in town Message-ID: So, Michael Schwern is in town tonight. I realise it's short notice, but if anyone wants to get together for an emergency social, let me know, and we'll see what we can sort out. -- Aaron Crane ** http://aaroncrane.co.uk/ From perl at minty.org Tue Apr 23 10:34:26 2013 From: perl at minty.org (Murray) Date: Tue, 23 Apr 2013 18:34:26 +0100 Subject: [Edinburgh-pm] thursday beer Message-ID: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> Thur 25th is the regular scheduled beer night, tho sadly I'm not going to be able to make it this month. Thus, I'll leave someone else to book a table etc if anyone is turning up :) Sorry to be awol -- hope to catch you all in May, if not sooner. M. From perl at aaroncrane.co.uk Wed Apr 24 03:04:34 2013 From: perl at aaroncrane.co.uk (Aaron Crane) Date: Wed, 24 Apr 2013 11:04:34 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> Message-ID: Murray wrote: > Thur 25th is the regular scheduled beer night, tho sadly I'm not going to be > able to make it this month. > > Thus, I'll leave someone else to book a table etc if anyone is turning up :) > > Sorry to be awol -- hope to catch you all in May, if not sooner. Shame to miss you this time round. I'll take care of booking a table at the Cumberland, if it sounds like we'll be quorate. Anyone? -- Aaron Crane ** http://aaroncrane.co.uk/ From stephen at jadevine.org.uk Wed Apr 24 03:45:16 2013 From: stephen at jadevine.org.uk (Stephen Quinney) Date: Wed, 24 Apr 2013 11:45:16 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> Message-ID: On 24 April 2013 11:04, Aaron Crane wrote: > Murray wrote: > > Thur 25th is the regular scheduled beer night, tho sadly I'm not going > to be > > able to make it this month. > > > > Thus, I'll leave someone else to book a table etc if anyone is turning > up :) > > > > Sorry to be awol -- hope to catch you all in May, if not sooner. > > Shame to miss you this time round. > > I'll take care of booking a table at the Cumberland, if it sounds like > we'll be quorate. Anyone? > I can't make it this week as I'm off to Mull fairly early the next morning. I note that there is a vague plan to meet Dave Cross for beer next Monday evening, sadly I shall still be away at that point. Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at dave.org.uk Wed Apr 24 03:44:48 2013 From: dave at dave.org.uk (Dave Cross) Date: Wed, 24 Apr 2013 11:44:48 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> Message-ID: <20130424114448.16244vcqfe1c2rhc@webmail.mag-sol.com> Quoting Stephen Quinney : > I note that there is a vague plan to meet Dave Cross for beer next Monday > evening, sadly I shall still be away at that point. Actually, it turns out that I'm going to be a bit busy on this trip and I won't be able to get out to see you next week. Sorry about that. I will, however, be back in Edinburgh at the end of May (w/c 26th) and I'll definitely be up for a beer at that point. Cheers, Dave... From Ian.Stuart at ed.ac.uk Wed Apr 24 07:40:25 2013 From: Ian.Stuart at ed.ac.uk (Ian Stuart) Date: Wed, 24 Apr 2013 15:40:25 +0100 Subject: [Edinburgh-pm] Dynamic library paths, that work in Test::More & under Apache/mod-perl Message-ID: <5177EED9.2060407@ed.ac.uk> So, I've some CGI scripts that work just ace... They pass a few hundred Test::More tests, and respond well as CGI scripts.... but there is one flaw: they have hard-coded paths in them Start with the working case - near the start of the script I have: use common::sense; use lib "/home/me/project_1/dev/perl5/lib/perl5/site_perl"; use Apache2::RequestRec; and this works fine under Apache/mod-perl, and passes the tests I throw at it. Of course, to move this to a testing server, I need to edit the 'use lib' path (for each script, obviously) - not clever.... so I want to abstract the library path *First attempt*: rely on PERL5LIB in the environment. Running the script from the command line is fine (@INC picks up PERL5LIB), but it fails under testing and through apache: "Apache2::RequestRec not found" - @INC does not have the stuff from PERL5LIB *Second attempt*: Add PerlSwitches -I/home/me/project_1/dev/perl5/lib/perl5/site_perl into an httpd conf file - nope: still fails (and I know the config file is being pulled in as both the cgi-bin and scriptAlias' defined in that file are working *Third attempt*: put something in a BEGIN block: BEGIN { unshift @INC, $ENV{BASE_APR_DIR}."/perl5/lib/perl5/site_perl"; warn Dumper(\%ENV); warn Dumper(\@INC); use Apache2::RequestRec; } %ENV has 'BASE_API_DIR' => '/home/me/project_1/dev' but @INC only gets '/perl5/lib/perl5/site_perl' Any thoughts on how to set @INC dynamically? ... so I can put a file into Source Control, and it will work whatever the root path is? -- Ian Stuart. Developer: ORI, RJ-Broker, and OpenDepot.org Bibliographics and Multimedia Service Delivery team, EDINA, The University of Edinburgh. http://edina.ac.uk/ This email was sent via the University of Edinburgh. The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. From stephen at jadevine.org.uk Wed Apr 24 08:11:07 2013 From: stephen at jadevine.org.uk (Stephen Quinney) Date: Wed, 24 Apr 2013 16:11:07 +0100 Subject: [Edinburgh-pm] Dynamic library paths, that work in Test::More & under Apache/mod-perl In-Reply-To: <5177EED9.2060407@ed.ac.uk> References: <5177EED9.2060407@ed.ac.uk> Message-ID: I would have thought the PerlSwitches directive would do the right thing. You could try instead adding the following to the relevant httpd.conf section: PerlSetEnv PERL5LIB /foo/bar/perllibs On 24 April 2013 15:40, Ian Stuart wrote: > So, I've some CGI scripts that work just ace... > > They pass a few hundred Test::More tests, and respond well as CGI > scripts.... but there is one flaw: they have hard-coded paths in them > > Start with the working case - near the start of the script I have: > > use common::sense; > use lib "/home/me/project_1/dev/perl5/**lib/perl5/site_perl"; > use Apache2::RequestRec; > > and this works fine under Apache/mod-perl, and passes the tests I throw at > it. > > Of course, to move this to a testing server, I need to edit the 'use lib' > path (for each script, obviously) - not clever.... so I want to abstract > the library path > > *First attempt*: rely on PERL5LIB in the environment. > Running the script from the command line is fine (@INC picks up > PERL5LIB), but it fails under testing and through apache: > "Apache2::RequestRec not found" - @INC does not have the stuff from PERL5LIB > > *Second attempt*: Add > PerlSwitches -I/home/me/project_1/dev/**perl5/lib/perl5/site_perl > > into an httpd conf file - nope: still fails > (and I know the config file is being pulled in as both the cgi-bin and > scriptAlias' defined in that file are working > > *Third attempt*: put something in a BEGIN block: > BEGIN { > unshift @INC, $ENV{BASE_APR_DIR}."/perl5/**lib/perl5/site_perl"; > warn Dumper(\%ENV); > warn Dumper(\@INC); > use Apache2::RequestRec; > } > > %ENV has > 'BASE_API_DIR' => '/home/me/project_1/dev' > but @INC only gets > '/perl5/lib/perl5/site_perl' > > > Any thoughts on how to set @INC dynamically? > ... so I can put a file into Source Control, and it will work whatever the > root path is? > > -- > > Ian Stuart. > Developer: ORI, RJ-Broker, and OpenDepot.org > Bibliographics and Multimedia Service Delivery team, > EDINA, > The University of Edinburgh. > > http://edina.ac.uk/ > > This email was sent via the University of Edinburgh. > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > ______________________________**_________________ > Edinburgh-pm mailing list > Edinburgh-pm at pm.org > http://mail.pm.org/mailman/**listinfo/edinburgh-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fontani at gmail.com Wed Apr 24 08:28:15 2013 From: fontani at gmail.com (Marco Fontani) Date: Wed, 24 Apr 2013 16:28:15 +0100 Subject: [Edinburgh-pm] Dynamic library paths, that work in Test::More & under Apache/mod-perl In-Reply-To: <5177EED9.2060407@ed.ac.uk> References: <5177EED9.2060407@ed.ac.uk> Message-ID: On Wed, Apr 24, 2013 at 3:40 PM, Ian Stuart wrote: > So, I've some CGI scripts that work just ace... > They pass a few hundred Test::More tests, and respond well as CGI > scripts.... but there is one flaw: they have hard-coded paths in them > > Start with the working case - near the start of the script I have: > use common::sense; > use lib "/home/me/project_1/dev/perl5/lib/perl5/site_perl"; > use Apache2::RequestRec; > [...] > Any thoughts on how to set @INC dynamically? > ... so I can put a file into Source Control, and it will work whatever the > root path is? Yes, assuming you have a "sane" directory structure in your repository: repo/lib repo/cgi-bin on your repo/cgi-bin/foo.cgi: use FindBin; # https://metacpan.org/module/FindBin use lib "$FindBin::Bin/../lib"; If the structure isn't like that, use the necessary amount of "../" to make it work. Example showing the script "works" (i.e. finds the right lib) no matter where you call it from: (~) $ mkdir -p /tmp/ian/{lib,cgi-bin}; cd /tmp/ian (/tmp/ian) $ echo "package A; warn 'Loaded A'; 1;" > lib/A.pm (/tmp/ian) $ echo 'use FindBin;use lib "$FindBin::Bin/../lib"; use A; print "works!\n";' > cgi-bin/foo.cgi (/tmp/ian) $ perl cgi-bin/foo.cgi Loaded A at /private/tmp/ian/cgi-bin/../lib/A.pm line 1. works! (/tmp/ian) $ cd /tmp (/tmp) $ perl cgi-bin/foo.cgi Loaded A at /private/tmp/ian/cgi-bin/../lib/A.pm line 1. works! (/tmp) $ cd (~) $ perl cgi-bin/foo.cgi Loaded A at /private/tmp/ian/cgi-bin/../lib/A.pm line 1. works! -- Marco Fontani From Ian.Stuart at ed.ac.uk Wed Apr 24 08:17:32 2013 From: Ian.Stuart at ed.ac.uk (Ian Stuart) Date: Wed, 24 Apr 2013 16:17:32 +0100 Subject: [Edinburgh-pm] Dynamic library paths, that work in Test::More & under Apache/mod-perl In-Reply-To: <5177EED9.2060407@ed.ac.uk> References: <5177EED9.2060407@ed.ac.uk> Message-ID: <5177F78C.8040105@ed.ac.uk> Answered my own question.... (is this some strange variation on "teddybear programming? [http://blog.adrianbolboaca.ro/2012/12/teddy-bear-pair-programming/]) Anyway.... so long as the libraries are in a known location relative to the scripts - eg: /home/me/project_1/dev/cgi-bin/myScript /home/me/project_1/dev/perl5/lib/perl5/site_perl then this seems to work: BEGIN { use FindBin; use lib "$FindBin::Bin/../perl5/lib/perl5/site_perl"; use lib "$FindBin::Bin/../testing"; use Apache2::RequestRec; } (I need the testing directory, to pick up the libraries used by the test-suite) On 24/04/13 15:40, Ian Stuart wrote: > So, I've some CGI scripts that work just ace... > > They pass a few hundred Test::More tests, and respond well as CGI > scripts.... but there is one flaw: they have hard-coded paths in them > > Start with the working case - near the start of the script I have: > > use common::sense; > use lib "/home/me/project_1/dev/perl5/lib/perl5/site_perl"; > use Apache2::RequestRec; > > and this works fine under Apache/mod-perl, and passes the tests I throw > at it. > > Of course, to move this to a testing server, I need to edit the 'use > lib' path (for each script, obviously) - not clever.... so I want to > abstract the library path > > *First attempt*: rely on PERL5LIB in the environment. > Running the script from the command line is fine (@INC picks up > PERL5LIB), but it fails under testing and through apache: > "Apache2::RequestRec not found" - @INC does not have the stuff from > PERL5LIB > > *Second attempt*: Add > PerlSwitches -I/home/me/project_1/dev/perl5/lib/perl5/site_perl > > into an httpd conf file - nope: still fails > (and I know the config file is being pulled in as both the cgi-bin and > scriptAlias' defined in that file are working > > *Third attempt*: put something in a BEGIN block: > BEGIN { > unshift @INC, $ENV{BASE_APR_DIR}."/perl5/lib/perl5/site_perl"; > warn Dumper(\%ENV); > warn Dumper(\@INC); > use Apache2::RequestRec; > } > > %ENV has > 'BASE_API_DIR' => '/home/me/project_1/dev' > but @INC only gets > '/perl5/lib/perl5/site_perl' > > > Any thoughts on how to set @INC dynamically? > ... so I can put a file into Source Control, and it will work whatever > the root path is? > -- Ian Stuart. Developer: ORI, RJ-Broker, and OpenDepot.org Bibliographics and Multimedia Service Delivery team, EDINA, The University of Edinburgh. http://edina.ac.uk/ This email was sent via the University of Edinburgh. The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. From perl at aaroncrane.co.uk Wed Apr 24 10:07:38 2013 From: perl at aaroncrane.co.uk (Aaron Crane) Date: Wed, 24 Apr 2013 18:07:38 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> Message-ID: I wrote: > I'll take care of booking a table at the Cumberland, if it sounds like > we'll be quorate. Anyone? Sorry, something's come up, and I won't be able to make it after all. I'm afraid someone else will need to book the table if needed. -- Aaron Crane ** http://aaroncrane.co.uk/ From cyocum at gmail.com Thu Apr 25 00:24:18 2013 From: cyocum at gmail.com (Chris Yocum) Date: Thu, 25 Apr 2013 08:24:18 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> Message-ID: <20130425072416.GA2142@gmail.com> Unfortunately, I will not be able to attend either. :( Chris On Tue, Apr 23, 2013 at 06:34:26PM +0100, Murray wrote: > Thur 25th is the regular scheduled beer night, tho sadly I'm not going to be > able to make it this month. > > Thus, I'll leave someone else to book a table etc if anyone is turning up :) > > Sorry to be awol -- hope to catch you all in May, if not sooner. > > M. > _______________________________________________ > Edinburgh-pm mailing list > Edinburgh-pm at pm.org > http://mail.pm.org/mailman/listinfo/edinburgh-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 230 bytes Desc: Digital signature URL: From wim.vanderbauwhede at gmail.com Thu Apr 25 02:22:40 2013 From: wim.vanderbauwhede at gmail.com (Wim Vanderbauwhede) Date: Thu, 25 Apr 2013 10:22:40 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: <20130425072416.GA2142@gmail.com> References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> <20130425072416.GA2142@gmail.com> Message-ID: Me neither, nor next month. But the next heretics should be fine. Cheers, Wim On 25 April 2013 08:24, Chris Yocum wrote: > Unfortunately, I will not be able to attend either. :( > > Chris > > On Tue, Apr 23, 2013 at 06:34:26PM +0100, Murray wrote: > > Thur 25th is the regular scheduled beer night, tho sadly I'm not going > to be > > able to make it this month. > > > > Thus, I'll leave someone else to book a table etc if anyone is turning > up :) > > > > Sorry to be awol -- hope to catch you all in May, if not sooner. > > > > M. > > _______________________________________________ > > Edinburgh-pm mailing list > > Edinburgh-pm at pm.org > > http://mail.pm.org/mailman/listinfo/edinburgh-pm > > _______________________________________________ > Edinburgh-pm mailing list > Edinburgh-pm at pm.org > http://mail.pm.org/mailman/listinfo/edinburgh-pm > -- If it's pointless, what's the point? If there is a point to it, what's the point? (Tibor Fischer, "The Thought Gang") -------------- next part -------------- An HTML attachment was scrubbed... URL: From miles at assyrian.org.uk Thu Apr 25 03:28:45 2013 From: miles at assyrian.org.uk (Miles Gould) Date: Thu, 25 Apr 2013 11:28:45 +0100 Subject: [Edinburgh-pm] thursday beer In-Reply-To: References: <20130423173426.GB6253@mooker.vm.bytemark.co.uk> <20130425072416.GA2142@gmail.com> Message-ID: <5179055D.9010601@assyrian.org.uk> I'm feeling grotty*, and am probably infectious, so I think I should stay away this month. Miles * nothing serious - cold, cough, headache, etc. Just ill enough to prevent me from concentrating on C++ coding, which as you'll appreciate is a terrible misfortune. I plan to recuperate in front of my now fully-operational Raspberry Pi media centre watching back episodes of Man Lab and Doctor Who. From miles at assyrian.org.uk Sun Apr 28 10:57:24 2013 From: miles at assyrian.org.uk (Miles Gould) Date: Sun, 28 Apr 2013 18:57:24 +0100 Subject: [Edinburgh-pm] Spot the bug Message-ID: <517D6304.9070902@assyrian.org.uk> Hi all, I recently encountered some Perl behaviour that surprised me, and thought you might be amused and/or able to provide further insight. Here's the buggy function: sub is_unate { my ($self, $idx) = @_; return ($self->true_count($idx) > 0) xor ($self->false_count($idx) > 0); } and here are the tests which allowed me to diagnose the problem: is($cubes->true_count(1), 1); is($cubes->true_count(2), 1); is($cubes->true_count(3), 1); is($cubes->true_count(4), 1); is($cubes->true_count(5), 1); is($cubes->false_count(1), 1); is($cubes->false_count(2), 0); is($cubes->false_count(3), 1); is($cubes->false_count(4), 1); is($cubes->false_count(5), 0); ok(!$cubes->is_unate(1)); # fails ok($cubes->is_unate(2)); ok(!$cubes->is_unate(3)); # fails ok(!$cubes->is_unate(4)); # fails ok($cubes->is_unate(5)); All tests pass apart from the ones marked "fails". So, my challenges: 1) Can you spot the bug in my code, and find a fix for it? 2) Can you explain why it makes sense for Perl to behave this way? Miles From wim.vanderbauwhede at gmail.com Sun Apr 28 12:14:39 2013 From: wim.vanderbauwhede at gmail.com (Wim Vanderbauwhede) Date: Sun, 28 Apr 2013 20:14:39 +0100 Subject: [Edinburgh-pm] Spot the bug In-Reply-To: <517D6304.9070902@assyrian.org.uk> References: <517D6304.9070902@assyrian.org.uk> Message-ID: Nice one! It's the binding of the xor, the correct code is return (($self->true_count($idx) > 0) xor ($self->false_count($idx) > 0)); return a xor b is equivalent to return(a) xor b. Wim On 28 April 2013 18:57, Miles Gould wrote: > Hi all, > > I recently encountered some Perl behaviour that surprised me, and thought > you might be amused and/or able to provide further insight. > > Here's the buggy function: > > sub is_unate { > my ($self, $idx) = @_; > return ($self->true_count($idx) > 0) xor ($self->false_count($idx) > > 0); > } > > and here are the tests which allowed me to diagnose the problem: > > is($cubes->true_count(1), 1); > is($cubes->true_count(2), 1); > is($cubes->true_count(3), 1); > is($cubes->true_count(4), 1); > is($cubes->true_count(5), 1); > > is($cubes->false_count(1), 1); > is($cubes->false_count(2), 0); > is($cubes->false_count(3), 1); > is($cubes->false_count(4), 1); > is($cubes->false_count(5), 0); > > ok(!$cubes->is_unate(1)); # fails > ok($cubes->is_unate(2)); > ok(!$cubes->is_unate(3)); # fails > ok(!$cubes->is_unate(4)); # fails > ok($cubes->is_unate(5)); > > All tests pass apart from the ones marked "fails". > > So, my challenges: > > 1) Can you spot the bug in my code, and find a fix for it? > 2) Can you explain why it makes sense for Perl to behave this way? > > Miles > ______________________________**_________________ > Edinburgh-pm mailing list > Edinburgh-pm at pm.org > http://mail.pm.org/mailman/**listinfo/edinburgh-pm > -- If it's pointless, what's the point? If there is a point to it, what's the point? (Tibor Fischer, "The Thought Gang") -------------- next part -------------- An HTML attachment was scrubbed... URL: From perl at aaroncrane.co.uk Mon Apr 29 03:10:21 2013 From: perl at aaroncrane.co.uk (Aaron Crane) Date: Mon, 29 Apr 2013 11:10:21 +0100 Subject: [Edinburgh-pm] Spot the bug In-Reply-To: <517D6304.9070902@assyrian.org.uk> References: <517D6304.9070902@assyrian.org.uk> Message-ID: [I delayed posting this for a while, so as to avoid spoilering it for anyone still playing along at home, so it has some overlap with Wim's message from yesterday; sorry about that.] Miles Gould wrote: > return ($self->true_count($idx) > 0) xor ($self->false_count($idx) > 0); > 1) Can you spot the bug in my code, and find a fix for it? > 2) Can you explain why it makes sense for Perl to behave this way? The "xor" operator (like "and" and "or") has lower precedence than "return", so the routine returns only whether true_count > 0. You can get the desired result with careful parenthesisation, or in this case (since the xdisjuncts are certain to be Perl's conventional truthy and falsy values) with the bitwise-XOR operator: return ($self->true_count($idx) > 0 xor $self->false_count($idx) > 0); return $self->true_count($idx) > 0 ^ $self->false_count($idx) > 0; Or in a variety of other ways: return $self->true_count($idx) > 0 != $self->false_count($idx) > 0; return !$self->true_count($idx) != !$self->false_count($idx); use List::Util qw; return 1 == sum map !$self->$_, qw; I did detect the bug by inspection ? you narrowed it down very conveniently, after all ? but B::Deparse is the go-to tool for ensuring that precedence isn't getting in your way: $ perl -MO=Deparse,-p -e 'sub f { return ($self->true_count($idx) > 0) xor ($self->false_count($idx) > 0) }' sub f { ((return ($self->true_count($idx) > 0)) xor ($self->false_count($idx) > 0)); } -e syntax OK The "-p" switch on the -MO=Deparse invocation is what enables the "parenthesise wherever possible" behaviour. This precedence lossage came up on p5p a couple of months ago, as it happens: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2013-02/msg00945.html The consensus seems to be that this behaviour is hard to justify (except as an accident of history), and Perl may at some point start issuing a warning for (unreachable) comparands on the right-hand side of a low-precedence logical operator whose left-hand side has compulsory flow-control effects. (Changing the precedence of "return" seems more likely to have unforeseen consequences, and also doesn't help with "die" or "next" or "last" or what-have-you.) I believe your example is a useful contribution to the debate, in that there's no high-precedence logical-XOR operator that could be recommended in this situation. -- Aaron Crane ** http://aaroncrane.co.uk/