unimatrix's Journal
http://use.perl.org/~unimatrix/journal/
unimatrix's use Perl Journalen-ususe Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners.2012-01-25T02:16:28+00:00pudgepudge@perl.orgTechnologyhourly11970-01-01T00:00+00:00unimatrix's Journalhttp://use.perl.org/images/topics/useperl.gif
http://use.perl.org/~unimatrix/journal/
Aspect-Oriented Programming in Perl
http://use.perl.org/~unimatrix/journal/857?from=rss
<p>
Aspect-oriented Programming comes to Perl.
</p><p>
I've uploaded an alpha distribution to CPAN, and it's also available
from <a href="http://codewerk.unixbeard.net/aspects/Aspect-0.04.tar.gz">http://codewerk.unixbeard.net/aspects/Aspect-0.04.tar.gz</a>.
There is a "perl-aspects" mailing list at <a href="http://www.astray.com/mailman/listinfo/perl-aspects">http://www.astray.com/mailman/listinfo/perl-aspects</a>.
</p><p>
What is Aspect-oriented Programming?
</p><p>
Aspect-oriented Programming (AOP) is a programming methodology
developed by Xerox PARC. The basic idea is that in complex class
systems there are certain aspects or behaviors that cannot normally
be expressed in a coherent, concise and precise way. One example
of such aspects are design patterns, which combine various kinds
of classes to produce a common type of behavior.
</p><p>
Another such aspect concerns debugging or tracing the flow of
execution. Maybe every time one of a set of subroutines is entered
or exited, you want to want to print a line telling you so. Normally
you would you the good old 'print' statement debugger, or maybe
you would actually use a custom Perl debugger or a C
module. But what if the profile produces too much output you're
not actually interested in? And a custom debugger usually does not
make for reusable, easily customizable code.
</p><p>
You might change the source of all those subroutines you're interested
in to print the desired information. When you are done debugging,
you remove the print statements again. That's a lot of effort and
can lead to bugs and oversights of its own. Furthermore, your code
is littered with unsightly print statements. If you want to change
the output, you have to change every print statement. If you add
a class, remember to add the print statements. It's a mess. Wouldn't
it be easier if you could influence the behavior of those subroutines
from the outside, like a switch you could flip to make them print
a statement when they're entered (in a consistent way, without
chance of forgetting to create or remove a print statement), then
flip the switch again to turn that behavior off?
</p><p>
That's what aspect-oriented programming is about. Aspects usually
concern many classes right across the class hierarchy. One says
that they "crosscut the program structure" and refers to them as
"crosscutting concerns".
</p><p>
Just like object-oriented programming (OOP) encapsulates the concepts
and functionality of individual classes and arranges them in a
class hierarchy, so does AOP encapsulate the concerns of many
classes and make those aspects or behvaviors reusable. In this way
AOP is orthogonal to OOP.
</p><p>
Aspects allow you to change the interaction of objects without
breaking their encapsulation. You don't change the behaviors of
the objects per se, but rather the way they behave at the seams,
at well-defined points during execution. For example, you can
intercept method calls, override methods, influence operators, and
generally influence the flow of execution in a way that isn't
possible without AOP.
</p><p>
Certainly you can achieve all these things without AOP, but it
would be a lot harder, less (or, more likely, not at all) reusable
and more error-prone. Just as you can simulate any object-oriented
program using non-OO techniques, but OO makes things just so much
easier.
</p><p>
By modularizing such concerns into aspects you ensure consistent
behavior across your project and don't depend on individual
programmers to follow a convention, say, on how to write security
or error checking. Indeed, it may not be necessary to for individual
programmers to write code for such concerns at all, if they're
centrally managed, from the outside, as it is, by aspects.
</p>unimatrix2001-10-03T09:29:38+00:00journalExporter::Simple
http://use.perl.org/~unimatrix/journal/368?from=rss
<p>Here is another module using attributes to simplify an API and hide implementation details. This time it's Exporter's API. Exporter::Simple, when used by a package, allows that package to define exports in a more concise way than using `Exporter'. Instead of having to worry what goes in `@EXPORT', `@EXPORT_OK' and `%EXPORT_TAGS', you can use two attributes to define exporter behavior:</p><p>
my @bar : Exportable(vars) = (2, 3, 5, 7);<br>
my $foo : Exported(vars) = 42;<br>
my %baz : Exported = (a => 65, b => 66);</p><p>
sub hello : Exported(greet,uk) { "hello there" }<br>
sub askme : Exportable { "what you will" }<br>
sub hi : Exportable(greet,us) { "hi there" }</p><p>You get the idea. I wasn't sure whether to emulate attributes for globals as well, but seeing that they're going to be in Perl 5.8.0, I'm going to wait until that's out before revising Exporter::Simple for a clean solution.</p><p>Enjoy. Feedback, as always, is welcome.</p>unimatrix2001-07-03T12:07:01+00:00journalPerl 6 proof-of-concept page
http://use.perl.org/~unimatrix/journal/351?from=rss
<p>
I've done a web page with information and links to Perl 5 modules that may be of interest to those discussing and implementing the Perl 6 language. Some of them are proof-of-concepts of Perl 6 features that the respective authors have implemented to show how things <i>might</i> work in Perl 6.
</p><p>
It's at <a href="http://www.codewerk.com/perl6/">http://www.codewerk.com/perl6/</a>.
</p><p>
Additions and suggestion for the page are welcome, please send them to <a href="mailto:marcel@codewerk.com">marcel@codewerk.com</a>.
</p>unimatrix2001-06-29T14:41:13+00:00journalScalar::Properties
http://use.perl.org/~unimatrix/journal/341?from=rss
<p>After reading a journal entry here, James Duncan sent me some pretty cool code showing how to get constant overloading and literals-as-objects working as intended. At that point, Scalar::Properties had become an inevitability. Let me amuse you with an excerpt of the module's synopsis:</p><p>
use Scalar::Properties;<br>
my $val = 0->true;<br>
if ($val && $val == 0) {<br>
print "yup, its true alright...\n";<br>
}</p><p>
my @text = (<br>
'hello world'->greeting(1),<br>
'forget it',<br>
'hi there'->greeting(1),<br>
);<br>
print grep { $_->is_greeting } @text;</p><p>
my $l = 'hello world'->length;</p>unimatrix2001-06-27T22:40:25+00:00journalGraphing Makefiles
http://use.perl.org/~unimatrix/journal/316?from=rss
<p>While playing with Makefiles, I had the urge to know what depends on what, hence GraphViz::Makefile was born. Coming to a CPAN near you rsn (i.e., after the most pressing other stuff gets done).</p>unimatrix2001-06-19T18:01:36+00:00journalYAPC::NA afterglow
http://use.perl.org/~unimatrix/journal/315?from=rss
<p>Revision: Without Damian, it would only have been half a conference, but without Kevin, Luc and Rich, there would have been no conference. Congratulations on organizing it and keeping it running smoothly.</p><p>On the flight back I was thinking about Ruby's literals-as-objects and realized that Perl can do this as well. By overloading constants, you can do things like</p><p>
print 42->times(3);<br>
print 'hello world'->reverse;</p><p>This could be used for runtime properties:</p><p>
return 0->true;</p><p>Now we need to override the test for definedness to also check for this property along with the value.</p>unimatrix2001-06-19T17:51:53+00:00journalYAPC::NA::END{}
http://use.perl.org/~unimatrix/journal/312?from=rss
<p>
YAPC::NA 2001 has finished. The time went by too fast, but it was
fun. Lots of ideas and inspirations. And I've met many people whom
so far I've only known from IRC or mail or newsgroups.
</p><p>
After the auction (where I actually bought a Ruby book and learned about its literal objects; nice) a bunch of us went for dinner in a lovely
French restaurant. We split up into several groups as we didn't
want to run the by-now-familiar risk of being turned away due to
large numbers, and Abigail, Leon, Isabel (of NY.pm) and freeside
had dinner, and we did something else afterwards, but I just can't
seem to remember what. Drinking, probably. Someone mentioned to
Abigail that he thought Klingon sounded like angry Dutch.
</p><p>
Saturday lunch we had the CPAN BOF, where we had to book a hotel
room as there were about 30 people. Brian, who apparently hadn't
slept all night, tried to convey his napc-idea (think CPAN + Napster
for binary builds... watch this space) and there were other intense
discussions. CPAN is great, and other languages would kill to have
something like it, but there's still lots to do.
</p><p>
Then dha, Skud, Leon, Brian and many more went down into the old
town to have a few drinks. A card game called "Chez Geek", the
blame protocol and a long-expected rain (with impressive impromptu
rivers down the sloped streets of Montreal) come to mind, in no
particular order.
</p><p>
Sunday I just walked around lots; dinner at Mr Yan's again; now
it's Monday and I'm writing this in a cafe just before going to
the airport. Will be able to upload it only in Vienna, though.
</p><p>
NB: At the airport now. Complete rip-off: on top of an expensive
flight, you have to pay CAD 10 when going through customs. "Oh, we
just thought we'd rip you off some more before upholding our end
of the deal."
</p>unimatrix2001-06-19T17:01:18+00:00journalYAPC::NA. Day 3. Lunch.
http://use.perl.org/~unimatrix/journal/303?from=rss
<p>We had some problems with wireless this morning, so this entry is a bit late. We don't do steenkin' wires.</p><p>Yesterday afternoon saw Damian's amazing "Life, The Universe and Everything" talk - where he mixes Conway's (no relation) Life, Klingon, Perl 6, Maxwell's Demonsa and more in a talk that you just had to be there - Damian at his best.</p><p>This morning mjd gave his talk on the dirty innards of the regex engine and the identity function. Next was Leon's talk about creating compilers for little languages using Parse::RecDescent or Parse::Yapp and abstract syntax trees; a concept with huge potential. Very exciting stuff.</p><p>And finally I had my debut as a Perl conference speaker: A lightning talk on Aspect-Oriented Perl. I was a bit nervous just beforehand, but up on stage, it quickly passed. Even Abigail liked the idea. Bodes well for my first full-fledged talk on "Handling Attributes" at YAPC::Europe.</p><p>Speaking of stages, for the last lightning talk, Damian and Brian took the stage to present Inline::Files in a Shakespeare-style play, in which, amongst other things, Damian (or rather, his character) called Brian('s character) the "puppet of an active state". It was an incredible talk and there were standing ovations at the end.</p><p>A Perl conference without Damian is no Perl conference.</p><p>Now I'm looking forward to the Perl 6 status meeting after lunch. Speaking of which...</p>unimatrix2001-06-15T17:06:36+00:00journalYAPC::NA. Day 2. Morning.
http://use.perl.org/~unimatrix/journal/291?from=rss
<p>Fixed two bugs in Inline with Brian Ingerson. Discovered that Data::Denter is very slow with big data structures with circular references. Worked some more on Getopt::Attribute, which is being uploaded as we speak.</p><p>I survived Abigail's Parse::RecDescent talk.</p><p>Lots of talk, some more ideas, smoked meat bof (bof good, beef bad - but hey, at least they don't have foot & mouth here, so you gotta get all the meat you can). Then a few of us went to a french restaurant / bistro. Pretty nice.</p><p>Currently I'm in gnat's Perl Internals class. Tonight will still see Brian's 'Data Denter & YAML' talk, Abigail's 'Return of the JAPHi' and Damian's 'Life, The Universe and Everything'. As well as the YAPC dinner.</p><p>More on that later.</p>unimatrix2001-06-14T13:24:19+00:00journalYAPC::NA Day 1. Morning.
http://use.perl.org/~unimatrix/journal/285?from=rss
<p>Setting up registration in the afternoon was pretty painless . Went to a restaurant a few blocks away from the conference in the evening. Which turned out to be somewhat of an uncoordinated effort as poor Mr Yan couldn't cope with 40 hungry hackers, so about half had to be turned away as he "didn't want to give them bad service". Which is a nice attitude.</p><p>Met up with acme, Brian Ingerson, dha, Gurusamy Sarathy and had some more crazy ideas which this time I'm *not* going to add to my long list of projects as the list is already, well, long.</p><p>Now it's early morning (though the jetlag still caused me to wake up at 5.30am, so no change there) and they're just setting up breakfast and registration behind us as acme, gnat and me are updating our journals.</p><p>Some minor and not so minor glitches: Michel Rodriguez can't make it, so something else has to be arranged presto - for a 1.5 hours talk that's supposed to start at 10am. Fun!</p><p>gnat brought a wireless network base station - but no power cable. Thankfully there's an abundance of hubs to compensate. Nothing wireless, though.</p><p>Ah, lenzo has just turned up. Which means we'll have airport again soon.</p><p>Later.</p>unimatrix2001-06-13T11:42:19+00:00journalyapc::europe talk
http://use.perl.org/~unimatrix/journal/279?from=rss
<p>Well, my talk on "Handling Attributes" for YAPC::Europe has been approved. Which means some work after returning to Vienna after YAPC::NA.</p>unimatrix2001-06-12T19:21:06+00:00journallive from yapc::na
http://use.perl.org/~unimatrix/journal/278?from=rss
<p>This is unimatrix, reporting live from YAPC::NA over the wireless network which lenzo and moi (to use the local language) have just set up. Registration starts at 4pm (which is 43 minutes from now - and counting).</p><p>I am indeed in shorts as it's pretty warm. Yesterday we had a bit of rain which was compensated by humidity today.</p><p>The bad news is that Larry can't make it as he is apparently rather ill; Damian will do his opening talk instead.</p><p>A few guys have already arrived and are hanging around the registration area.</p><p>My lightning talk (aspect-oriented perl) coincides with acme's compiler talk, so I'll ask mjd to move my talk to the back. Trying to explain this concept in five minutes is madness anyway. The title should be "The Reduced Hacker Company: The Compleat Aspect-Oriented Perl (abridged)".</p><p>I'll send updates if and when I get around, although with wireless, it should be a lot easier.</p>unimatrix2001-06-12T19:19:09+00:00journalExporter::Simple, networking simple
http://use.perl.org/~unimatrix/journal/261?from=rss
<p>Worked some more on Exporter::Simple, which uses attributes to make exporting variables (even lexicals!) and subroutines simple as you don't have to worry about Exporter's arrays and hashes.</p><p>Exporting lexicals was made possible/easy using Robin Houston's PadWalker module, which allows you to see which lexicals are defined in your scope.</p><p>Acme mentioned wireless networking in his journal; I have to agree that it's pretty cool wandering about with your powerbook downloading stuff - and no wires whatsoever. Let's see if we can get together a wireless network for YAPC::NA.</p><p>The lightning talk on aspect-oriented Perl has been approved, but it seems scary now to try and explain aspects in five minutes - apart from the fact that I've spent all time scheduled for aspects on Exporter::Simple... Oh well; it'll be a brief overview.</p>unimatrix2001-06-07T07:42:10+00:00journalEntering ideas. Aspects.
http://use.perl.org/~unimatrix/journal/238?from=rss
<p>Having a little notebook (of the paper variety) to jot down quick ideas is a good thing (I have a Palm but can never quite bring myself to use it); but every now and then the notes become so extensive that you have to start entering them lest you have to carry your laptop, notebook, additional loose pieces of paper, the Palm (that does get used from time to time) etc. Need I go on?</p><p>So it's typing time. Having it all on disk makes it easier to backup those ideas, but it's just no match for reading from real paper.</p><p>Coming soon to a Perl interpreter near you: I've had some more ideas for aspect-oriented perl; more on which at YAPC::North::America. Basically it's about being able to influence almost any point during execution from the outside, without having to rewrite (and un-rewrite later) loads of modules to install (and uninstall) certain behavior. Sounds abstract, I know. Read http://www.parc.xerox.com/csl/projects/aop/ and aspectj.org for details.</p>unimatrix2001-06-01T14:40:47+00:00journalAttributes II
http://use.perl.org/~unimatrix/journal/227?from=rss
<p>After doing some more experiments and work with attributes, there are now two more modules on CPAN: Attribute::Util, which provides four general-purpose attributes (Memoize, Abstract, Alias, SigHandler) and Attribute::Overload, which allows you to declare a subroutine to be an overload handler for one or more operations.</p><p>I've also submitted a proposal for a talk on attributes to YAPC::Europe (yes, I know the CFP deadline is today...)</p><p>Work still continues on Exporter::Simple, another module that uses - surprise! - attributes to make life easier if you want to export variables and subroutines. Damian is about to release a new version of Attribute::Handlers and so I'm delaying the release of Exporter::Simple; there are still a few things to be implemented.</p><p>I've quit my job (it was the end of a project) to spend all summer hacking Perl (ok, I'll try to get out every now and then...), and you just get so much more done if you can work a) on what you really love to do, b) in concentration, c) without commercial pressures.</p><p>I'll start looking for another job in September, but again it'll only be to fund some more time on what's really important.</p>unimatrix2001-05-31T07:40:25+00:00journalFun with Attributes
http://use.perl.org/~unimatrix/journal/183?from=rss
<p>Got into attributes today. Damian's Attribute::Handlers really makes this easy. The result so far are the following three modules:</p><p>Attribute::TieClasses - attribute wrappers for CPAN Tie classes. The following lines load in Tie::Scalar::Timeout and tie()s $k with those options</p><p>
use Attribute::TieClasses;<br>
my $k : Timeout(EXPIRES => '+2s');</p><p>Attribute::Memoize - Attribute interface to Memoize.pm</p><p>
use Attribute::Memoize;<br>
sub fib<nobr> <wbr></nobr>:Memoize {<br>
my $n = shift;<br>
return $n if $n 2;<br>
fib($n-1) + fib($n-2);<br>
}</p><p>Attribute::Abstract - implementing abstract methods with attributes</p><p>
package SomeObj;<br>
use Attribute::Abstract;</p><p>
sub new {<nobr> <wbr></nobr>... }<br>
sub write : Abstract;</p><p>Now, if properties (in Perl 6 jargon) were modifiable at runtime, it would open the door to aspect-oriented programming. There might be a little talk at YAPC::NA and/or YAPC::Europe on that; so far there is a proof-of-concept implementation of aspects using the flexibility afforded by the debugger. More on that later.</p>unimatrix2001-05-18T20:38:31+00:00journalWhy Perl?
http://use.perl.org/~unimatrix/journal/16?from=rss
<p>I yearn for a sense of common purpose, with Open Source and<br>Perl hackers, beyond competing for the next job. We as<br>hackers are in the happy position of using and building<br>those tools that further sharing ideas. I'm optimistic that<br>the 21st century can be a blissful time of shared<br>conviction.</p><p>Why Perl?</p><p>Perl is not just a way of telling the computer what you<br>mean, it is also the basis of a thriving culture. The Perl<br>Mongers are one of the most important aspects of this<br>culture. They have chapters throughout the world, with new<br>ones being built all the time. Meetings, mailing lists, IRC<br>channels and grassroots conferences produce an energy and<br>exchange of ideas. This is helped by flat structures; even<br>the most brilliant minds within the Perl community are just<br>regular guys you don't have to be afraid to talk to.</p><p>Certainly one reason for this thriving culture is that fun<br>can be had with Perl, since the language is expressive and<br>flexible enough to allow you to write code the way you want,<br>be it obfuscated or poetic (the two are not necessarily<br>mutually exclusive), as a one-liner or as beautifully<br>structured object systems. There's more than one way to do<br>it.</p><p>Perl also allows you to do crazy things in easy and powerful<br>ways. Quantum-superpositioned variables that can be in<br>several states at the same time, or variables whose value<br>expires after some time; writing code in Latin or data<br>structures that flexibly bend and morph into any shape you<br>want, are but a few things possible in this rather natural<br>computer language - no contradiction in terms implied.</p><p>Elaborate code repositories, automated testing facilities,<br>recorded history; and now, the first development grant<br>sponsored by a community. Within two weeks of making public<br>the idea of sponsoring Damian Conway for a year to<br>exclusively work on Perl, the notion had become a reality.<br>Perl generates quite a bit of money, and good programmers<br>are sought-after, well-paid and tend to be generous and<br>helpful - as it has turned out, not only with advice. If<br>this concept works, it could spawn a wave of communities<br>self-sufficiently honoring brilliant minds. It is in this<br>environment that a sharing of ideas and common purpose is<br>fostered and achieved.</p>unimatrix2001-04-09T15:29:28+00:00journalOpen Source and Artistic Movements
http://use.perl.org/~unimatrix/journal/15?from=rss
<p>It's easy to make plans when you're on holiday or have some<br>spare time, but once you're back home the day-to-day chores<br>will quickly catch up with you. Nevertheless, I think I've<br>learned something in the past year. Those two months in the<br>summer of 2000 that I've taken as more or less a sabbatical<br>have shown just how far you can get and how much fun it can<br>be when you're don't have to go to a regular nine-to-five<br>job. And experiences in London, meeting the open-source<br>community, namely in the form of the London Perl mongers and<br>taking part in the London Perl conference, have shown me<br>that, unless you're part of some culture you can relate to,<br>the life of a hacker can be a solitary one. However, when<br>you're engaged in open-source activities, you can immerse<br>yourself in this hacker culture, and it feels good and gives<br>you energy.</p><p>There are some concepts which may appear initially unrelated<br>to computer programming, but are compatible with that<br>mindset. The idea of living a bohemian lifestyle, of<br>exploring the artist within yourself (and hacking certainly<br>can be an art form), the comparison with the French painter<br>or poet around the fin-de-siecle who takes part in new<br>artistic movements, maybe even political discussions with<br>other artists in some Parisian cafe, drinking Absinthe (the<br>poet's third eye), is very appealing. In his talk at the<br>yapc::Europe 19100, Simon Cozens related the open-source<br>hacker to such artists. But how do you achieve such a state<br>of the free spirit?</p><p>The principal downside of programming for fun is the lack of<br>income. Only rarely can one find a job, temporary or<br>permanent, that allows oneself to indulge in open-source<br>projects. My rather temporary solution for this has been a<br>three-month visit to London, in a rather well-paid project.<br>London is expensive, Vienna is not, so the idea was to earn<br>money in London and spend it in Vienna. Back in Vienna, I'll<br>try to find similar set-ups; well-paid, short-term<br>commercial projects followed by periods of practising your<br>own hackerly art. Unfortunately, income taxation in Austria<br>is very high, so it would pay off a lot more working in<br>London, but then again that's not home.</p><p>There are, of course, other ways to make a living. Having<br>taught a few small Perl-classes, I found that to be<br>challenging and fun at the same time. So I might offer some<br>open Perl training with the Vienna.pm and Linux user group<br>folks, hoping to build up experience and a reputation, so I<br>can then offer these services to companies. Speaking of the<br>Vienna Perl mongers, they seem to be lazy beyond virtue when<br>it comes to organizing meetings and other activities, so I'd<br>like to encourage socal contact between those hackers.</p>unimatrix2001-04-09T15:28:37+00:00journalHello, World!
http://use.perl.org/~unimatrix/journal/14?from=rss
<p>The first entry into a new diary.</p><p>There will be notes of a more general nature, not specific<br>to a particular project.</p>unimatrix2001-04-09T15:26:58+00:00journal