Created
April 21, 2010 07:50
-
-
Save leto/373558 to your computer and use it in GitHub Desktop.
Security Layer in PIR for PL/Parrot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.namespace ["PLParrot"] | |
.sub open :method | |
.param pmc args :slurpy | |
print "Attempt to open " | |
$S1 = args[0] | |
say $S1 | |
.end | |
.sub copy :method | |
.param pmc from | |
.param pmc to | |
print from | |
print "=" | |
say to | |
.end | |
.sub rename :method | |
.param pmc from | |
.param pmc to | |
print "Attempt to copy file " | |
print from | |
print " to " | |
say to | |
.end | |
.namespace [] | |
.sub _ :load :init :anon | |
load_bytecode 'P6object.pbc' | |
.local pmc p6meta, interp, classes, classid | |
p6meta = get_root_global ["parrot"], "P6metaclass" | |
p6meta.'new_class'('PLParrot') | |
interp = getinterp | |
classes = interp[0] | |
classid = classes['PLParrot'] | |
set classes['FileHandle'], classid | |
set classes['File'], classid | |
.end | |
.sub main :main | |
.local pmc fh, file | |
new fh, 'FileHandle' | |
fh.'open'("/etc/passwd") | |
new file, 'File' | |
file.'rename'('foo','bar') | |
.end | |
The above code prints: | |
Attempt to open /etc/passwd | |
Attempt to copy file foo to bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment