ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
caller with no sub scope
by Gaal Yahas other posts by this author
Jun 17 2005 11:27PM messages near this date
Re: AUTLOAD and $_ | When can I take given as read?
In Perl 5, "caller EXPR" returns undef if the caller is top-level code. If
you need it, you can still get file, line, and package information
(this last is important for "import" subs) by using "caller" with the
EXPR-less form.

How do you do that in Perl 6? I'd been working with this presumed
signature:

     multi sub caller (Class ?$kind = Any, Int +$skip = 0, Str +$label)
             returns Control::Caller is primitive is export is safe { ... }

And an implementation which *always* expected a VCode frame (to check
$kind against). Obviously, this leaves no way to peek at frames with no
&?SUB, i.e., the top level.

The hacky way to solve this is to stipulate that kind=> Any actually
means something so general that it matches things that are not VCode
at all. The cleaner way in terms of formalism is to allow $kind to be
undef (actually, *default* to it), in which case it functions as that
wider-than-Any qualifier.

I'd go with the second way, since I think it leaves us with DWIMmy
usage. This will start working, which is good:

     sub import() {     # (do we still have that?)
         die "I'm not speaking with you!" if caller().package ~~ Rival;
     	...
     }

Anyone spot any problems?

-- 
Gaal Yahas <gaal@[...].org> 
http://gaal.livejournal.com/

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved