Source: Tim Bunce blog, http://blog.timbunce.org/2008/03/08/perl-myths/
Perl Ideas, Articles, News..
Friday, March 28, 2008
Friday, January 18, 2008
A Tour of Parrot
Tomorrow is Parrot’s monthly New Contributor Day, as we prepare for the 0.5.2 release on 15 January 2008. Before you join us in #parrot on irc.perl.org, you might peruse three articles I wrote for Linux Magazine last year.
A Tour of Parrot explains the philosophy of the project and several of the design decisions we’ve made.
Programming PIR explains the native programming language of Parrot, an assembly language full of high-level language features and syntactic shortcuts.
Programming Reusable PIR shows how to build actual programs in PIR.
Now that the Parrot Compiler Toolkit has reached its second stage of evolution, you don’t have to write PIR to build your own compiler on Parrot. I hope to continue the series soon by showing how simple writing a working compiler for a non-toy language can be with this new technology.
Posted by
Nick
at
7:01 AM
0
comments
Links to this post
Parrot 0.5.2 Released
Bob Rogers just released Parrot 0.5.2. This monthly release includes a couple of interesting new features.
First, we’ve managed to bundle up Patrick Michaud’s Rakudo (that’s the implementation of Perl 6 on Parrot) such that you can type make perl6 on Unixy platforms and make perl6.exe on Windows and get a working standalone Perl 6 binary. This is experimental and we hope to iron out some installation and deployment issues by next month’s release, but it was important to demonstrate our progress.
The second new feature is a toolkit for starting your own compiler. Max Mohun built a prototype several months ago, and we’ve added a stripped down version for now that builds the skeleton of a compiler for you using the Parrot Compiler Tools. I mentioned the LOLCODE compiler in What the Perl 6 and Parrot Hackers Did on Their Christmas Vacation; this is how Simon and Company were able to get LOLCODE up and running so quickly.
If someone asks nicely, I might even make it possible to create a standalone LOLCODE compiler executable. Where else are you going to get patch explanations like:
The bare expression before anO RLY?should both setITand be used as a test in theO RLY?, but it should only be evaluated once.
(See Perl RT #49808.)
Posted by
Nick
at
6:59 AM
0
comments
Links to this post
Wednesday, October 17, 2007
Adding Show Source to Perl Exceptions by Perl.com
Nice article by Chromatic from Perl.com, so here it is:
listen
Friday October 12, 2007 6:00AM
by chromatic in Technical
Adrian Howard asked on PerlMonks is there any way to access the contents of a block eval?. After catching an exception in Perl, can you see the source code that threw the exception, without using a source filter?
I wrote many of my parts of Perl Hacks by trying to do impossible things that no one had ever done before. (I don’t know that no one had ever done them, but I’d never heard of them before, which was close enough.) Because everyone thought it was impossible, I decided to try.
Introspection
The B modules prove Perl-level access to the internal data structures which represent executing Perl programs. They’ve been around in the core for years, but they rarely get much attention. (Their interfaces are occasionally opaque, and the documentation isn’t always clear.)
Plenty of Perl programmers know that B::Deparse is usually very good at making idiomatic code clearer. From the command line, run perl -MO=Deparse some_messy_file.pl to get a better sense of what’s happening. (This is your second stop after Perl::Tidy.)
Fewer Perl programmers know that you can use B::Deparse from within your programs. Given a subroutine reference and a B::Deparse object, call the coderef2text() method on the object, passing the reference, to receive deparsed source code.
I knew that much was possible before I read Adrian’s post. I figured I could start from there to see what I could find.
More Introspection
I decided to set a couple of constraints. First, I wanted a simple function which could return the source code of the previous eval block. Second, I decided that I’d only handle the case where the eval block occurred inside a Perl subroutine. With a little bit of work, my solution will also work when the eval occurs at the top level of a program, but I didn’t want to code around every corner case in this proof of concept. Finally, I decided that I would assume that there would only be one eval block on a line. That’s a reasonable assumption as well.
I wrote a little bit of code for a test case: sub main
{
my $x = 10;
my $y = 20;
eval { my $x = 1; my $y =
$x; die 'aaaarrrr' };
print( $@, get_eval_text( __LINE__ - 1 ) ) if $@;
}
main();
The only interesting code is the call to get_eval_text(). It takes one argument, the line number of the eval call. This was my first interface, and it could be slightly better. In particular, the __LINE__ directive (congruent to #line in C) is unnecessary. As well, the line number is also unnecessary; it’s possible to find this precise call in the optree and then the most recent eval by walking backwards, but that’s polish now that I know it’s possible.
get_eval_text() is reasonably simple, too: sub get_eval_text
{
my $start = shift;
# turn the invoking
subroutine into a B::Op-derived object
my ($package, $sub) = (caller(1))[0,
3];
my $subref = do { no strict 'refs'; *{ $package . '::' . $sub }{CODE} };
my $cv = B::svref_2object( $subref );
# create a B::Deparse object and
give it a sub to deparse (in part)
my $deparse = B::Deparse->new();
$deparse->{curcv} = $cv;
# search the optree for the first op on the
eval {} line
my $op = deparse_from($cv->START, $start);
# and deparse
from that op
return $deparse->deparse($op, 0) if $op;
}
There’s a little more magic here. First, it uses the caller() operator to get information about the calling subroutine — the one that contains the eval block. From there, it only takes a symbolic lookup to get a reference to that subroutine. (Yes, getting a reference to an anonymous subroutine would be slightly more difficult, but certainly not impossible. With that reference, the code then calls B::svref_2object to receive a B::CV object.
Optrees
Perl represents all subroutines internally with data structures called CVs (for Code Value). B wraps these into objects with the appropriate methods. A CV contains pointers to its optree, which is a tree of opcodes that Perl executes. To see a textual representation of the optree, use B::Concise.
Next, the code creates a B::Deparse object. Instead of immediately passing it the subroutine reference, the code sets a property of the object to the B::CV object. This is because I didn’t want to deparse the entire subroutine, just the eval block. B::Deparse doesn’t really quite have a public interface for the approach I took, yet.
The next call is to deparse_from(), a function which takes the first op (first in execution order) of the subroutine as well as the line number on which the eval block occurs. It returns a B::Op or derivative object representing the branch of the block.
Finally, the result gets passed to the B::Deparse object’s deparse() method, if there’s any result. That method returns the deparsed code of just that branch of the optree.
Here’s the code for deparse_from(): sub deparse_from
{
my ($start, $line) = @_;
for (my $op =
$start; $$op; $op = $op->next())
{
# look for nextstate ops
next
unless $op->isa( 'B::COP' );
# ... specifically the one representing the
start of the eval {}
next unless $op->line == $line;
# then grab the
sibling op in the tree: leavetry
return $op->sibling;
}
return;
}
The heart is a loop, which just walks the optree from one op to the next, in execution order. The optree for main() looks like:
$ perl -MO=Concise,main get_at_eval.pl
main::main:
m <1>
leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->m
1
<;> nextstate(main 2016 get_at_eval.pl:49) v/2 ->2
4 <2>
sassign vKS/2 ->5
2 <$> const[IV 10] s ->3
3 <0>
padsv[$x:2016,2021] sRM*/LVINTRO ->4
5 <;> nextstate(main 2017
get_at_eval.pl:50) v/2 ->6
8 <2> sassign vKS/2 ->9
6
<$> const[IV 20] s ->7
7 <0> padsv[$y:2017,2021] sRM*/LVINTRO
->8
9 <;> nextstate(main 2021 get_at_eval.pl:51) v/2 ->a
b
<@> leavetry vKP ->c
a <> entertry(other->b) v ->n
n <;> nextstate(main 2018 get_at_eval.pl:51) v/2 ->o
q
<2> sassign vKS/2 ->r
o <$> const[IV 1] s ->p
p
<0> padsv[$x:2018,2020] sRM*/LVINTRO ->q
r <;> nextstate(main
2019 get_at_eval.pl:51) v/2 ->s
u <2> sassign vKS/2 ->v
s
<0> padsv[$x:2018,2020] s ->t
t <0> padsv[$y:2019,2020]
sRM*/LVINTRO ->u
v <;> nextstate(main 2020 get_at_eval.pl:51) v/2
->w
y <@> die[t5] vK/1 ->b
w <0> pushmark s ->x
x <$> const[PV "aaaarrrr"] s ->y
c <;> nextstate(main
2021 get_at_eval.pl:52) v/2 ->d
- <1> null K/1 ->-
e
<> and(other->f) K/1 ->m
- <1> ex-rv2sv sK/3 ->e
d
<#> gvsv[*@] s ->e
l <@> print sK ->m
f <0>
pushmark s ->g
- <1> ex-rv2sv sK/3 ->h
g <#> gvsv[*@]
s ->h
k <1> entersub[t9] lKS/TARG,3 ->l
- <1> ex-list
lK ->k
h <0> pushmark s ->i
i <$> const[IV 51] sM
->j
- <1> ex-rv2cv sK/3 ->-
j <#> gv[*get_eval_text] s
->k
get_at_eval.pl syntax OK
I realize that’s a big chunk of information, but you don’t have to understand much about it. The numbers and letters to the far left represent the execution sequence. The START op of the code is 1, the next op is 2, and so forth.
The loop walks the ops, looking for COP (Control OPeration) nodes. The concise output represents node types symbolically; <;> indicates a COP. Note that they’re all named nextstate. These nodes more or less represent sequence points in the program. They also have a line attribute, which the loop uses to see if it’s reached the correct line number for the eval block. Otherwise, it keeps stepping through the code.
When the loop has reached the correct line, it grabs the sibling node (in tree order, not execution order) which is (probably) the leavetry node representing the eval block. Following the next pointer would lead to the entertry op, which isn’t sufficient to deparse the whole block structure as it isn’t the parent op of the entire block. Don’t worry if you don’t follow all of that; just trust me that a parent op executes only after all of its children have executed in the proper order.
The leavetry op is deparseable, and it gives only the eval block and not any other parts of the subroutine.
Concluding Thoughts
I mentioned earlier that there are a couple of optimizations. Because caller knows the line number of the call to get_eval_text(), it’s possible to scan the relevant CV optree for the COP with that line number, then scan backwards for the most recent leavetry sibling. That heuristic will probably work, but it’s more complex than I wanted to show here (and also it only occurred to me as I started to write this explanation.)
It’s also possible that there will be no calling subroutine. In that case, there are a couple of B functions that can grab the top-level CV in the invoking package for introspection. I also didn’t show that because it would complicate the code.
If you run this code, you’ll see that the deparsed code block likely contains the use of the warnings and strict pragmata. I didn’t look in B::Deparse how to disable ambient pragmas, mostly because I considered removing that code also polish. However, it might be useful to see what is in effect in the block anyway.
I realize that Lisp-like languages make this sort of behavior much easier, but it’s at least possible in Perl, even if the interface isn’t always easy. One of the plans for Parrot is to make this introspection much less painful. Once that’s in place, it should be possible to give better introspective and manipulation capabilities to all languages running on Parrot, from each other.
Posted by
Nick
at
6:04 AM
0
comments
Links to this post
Perl news from PerlCast
Source: http://perlcast.com/2007/09/14/perl-news-13-sep-2007/
Interview Audio
Welcome to Perlcast. This is your host, Randal Schwartz with another round of Perl news.
Let’s kick things off with a little conference and workshop news.
YAPC::Europe 2007 has released some conference videos on YouTube under the tag ‘yapceu07′. There are only a few videos posted right now, but expect more to follow.
Of course, YAPC::Europe 2007 isn’t the only YAPC to release videos recently. YAPC::Europe 2002 have posted videos from the Munich conference on YouTube under the tag ‘yapceu02′. Of course, the 2002 organizers have a pretty good excuse for just now posting their videos… the conference was held three years before the existence of YouTube!
Since we are on the topic of videos, I might as well mention that the London.pm Teach-In videos can now be found on Blip.tv at jtweed.blip.tv. There are videos for each of the four sessions available. Be warned that the audio on the last session cuts out near the end due to technical difficulties at the teach-in.
Enough about past events, let’s move on to what is on the horizon.
First a reminder that the Pittsburgh Perl Workshop is just around the corner. The workshop will be held on October 13-14, 2007 at the University Center on Carnegie Mellon University’s Oakland campus. And, don’t forget that in addition to the workshop, there will be a “From Zero To Perl,” a special course for programmers new to the Perl programming language. There is an additional registration fee of $65 to take this course. Please select either the “Regular + From Zero To Perl” or “Student + From Zero To Perl” options when registering. Seating in this course is limited so register today before it’s too late!
Next, for those brave souls with thick coats, the Minneapolis Perl Mongers have announced a one-day Perl workshop to be held on February 16th, 2008. The workshop is appropriately named Frozen Perl and will be an all-day workshop held at the University of Minnesota. More information can be found at frozen-perl.org, as well as, a link the Frozen Perl’s call for speakers. The theme of the workshop is “Perl in Practice”. If you want to take a shot at being a speaker, submit your abstract soon.
In YAPC news, Copenhagen, Denmark has been selected to host YAPC::Europe 2008. Copenhagen faced stiff competition from Braga, Portugal and the Informatics department of Wellcome Trust Sanger Institute in Cambridge, United Kingdom. Though the Wellcome Trust didn’t win the bid, their submission marks the first from a non-Perlmonger group.
Copenhagen.pm has hosted several Nordic Perl Workshops and is expected to pull together a wonderful conference. Congratulations Copenhagen.pm.
We’ll wrap up the social Perl news by welcoming a new PM group to the mix. Leeds.pm is getting started with an inaugural meeting on tentatively set for the 7th December. leeds.pm.org doesn’t seem to running yet but there is a mailing list. You can find the link at Perlcast.com (http://www.hexten.net/mailman/listinfo/northofengland-pm)
On a slightly more technical slant, there have been a few update on search.cpan.org. CPAN search has added gravatar icons to author pages so that CPAN users can make a human connection to the people behind the code that thye are using. CPAN authors can add their own gravatar by signing up to gravatar.com using their CPAN email alias. Also, search results now display module ratings from cpanratings.perl.org. This allows for searches to quickly get an idea of which modules might work best for them.
While on the topic of CPAN, the PAUSE administrators recently put out an important announcement. They are planning to do a little house keeping on the CPAN Modules List. They intend to remove old namespace reservations which have been registered with the modules mailing list but for which there never has been an actual implementation on CPAN. This will apply to all unused registrations from May 2007 and earlier. The admins will send an email to every PAUSE author who has an unused namespace asking them to contact the modules-at-perl-dot-org mailing list about the issue. Registrants have until December, at which time the namespaces will then be made available again. If you’ve registered a namespace and haven’t used it, be sure to watch your inbox.
CPAN Testers have started an IRC discussion channel since the #cpantesters channel has gotten a little noisy due to smoke reports. Now testers can have conversations on #cpantesters-discuss at irc.perl.org.
You’ve seen the ‘digg it’ links on people’s websites and news stories. What about Perl-related stores? Is there an easy way to have people submit your post as a story to use.perl.org? Now there is. Visit use.perl.org to grab the two lines of JavaScript that make the majic happen. The submitter doesn’t need to have an account on use.perl.org, but people with an account can add a description of the story they’d like to submit.
Believe it or not, Fall is here and it is time for the Fall 2007 issue of The Perl Review. In it’s fourth year of print publication, the magazine has a new design that packs in more Perl into the same number of pages of older addtions. In this issue: Templating My Output — Alberto Simões; Making My Own CPAN — brian d foy; Programming Parrot: NCI — Jonathan Scott Duff; Komodo Test Drive — Jim Brandt; Named Captures in Perl 5.10 — brian d foy; and much more.
The Perl Foundation has awarded a grant to Shlomi Fish to create a reusable parser for the syntax of MediaWiki, the popular open-source wiki engine that powers sites such as Wikipedia and Wikiquote. The deliverables of the grant are a CPAN module and a Kwiki plugin for using this MediaWiki syntax in Kwiki wikis, enabling people to create Perl projects that can parse its syntax and create compatible wikis. This grant is a second for Shlomi, who successfully completed a grant for XML::RSS improvements earlier this year.
If you want to contribute to the Perl community and get paid for it, consider proposing a grant to The Perl Foundation. If you would like to contribute and have no idea what to do, check out TPF’s grant suggestions on their website.
Do you have a reasonably connected server with a static IP address? If so, you might be eligible to join the NTP Pool. The CPU requirements for ntpd are so small that you will hardly realize that it’s there and with that small bit of CPU, you’ll be helping millions of computer users around the world. In addition, if you are able to setup a GPS antenna then you can apply for free GPS devices. More information can be found at www.pool.ntp.org/meinberg.html.
exuberant ctags 5.7 is out with improved Perl support including support for ‘package’ keyword, multi-line subroutine, package, and constant definitions, optional subroutine declarations, formats, and much more. ctags is easy to use and is easy for module authors to add targets for in their distributions.
There have been a few Perl books released recently. At OSCON, brian foy’s “Mastering Perl” came hot off the press. Now, Stas Bekman and Jim Brandts “mod_perl2 User’s Guide” was just been published by Onyx Neon. Look for a book giveaway soon at Perlbuzz.com.
And finally, ohloh.net is a social networking site for open source projects. There are a few Perl-based projects out there waiting for reviews and others that need to be submitted. Check out ohloh.net and get a slightly different look at the open source projects that you use every day.
Posted by
Nick
at
6:01 AM
0
comments
Links to this post
Tuesday, September 11, 2007
Surf the Web Like Tom Cruise
well, nothing like a little science fiction to liven up your day, but what if it were real... ?
read more | digg story
Posted by
Nick
at
5:34 AM
0
comments
Tuesday, August 28, 2007
REVIEW: Walking through the Web: Web2Walk
Web 2.0 provides us with all sorts of ways to check our favorite sites. However, for the most part, we’ve been constrained primarily to using browsers, email and RSS Feeds. With the dawn of this second internet, there seem to be a plethora of new ways to surf the internet. Walk2Web takes old paths and give them an upgrade.
read more | digg story
Posted by
Nick
at
2:52 PM
0
comments
Tuesday, August 21, 2007
New Way ScreenSaver
The New screensaver show snapshots of sites, that people surf through Walk2Web.com.ScreenSaver is based on screenshots of sites in resolution of 1024x768, but it tries to approximate resolution if needed without losing of quality.
read more | digg story
Posted by
Nick
at
8:38 AM
0
comments
