Skip to content

Instantly share code, notes, and snippets.

@leto
Created April 21, 2010 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leto/373558 to your computer and use it in GitHub Desktop.
Save leto/373558 to your computer and use it in GitHub Desktop.
Security Layer in PIR for PL/Parrot
.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