in reply to Re^5: User access controlled by subroutine attribute.
in thread User access controlled by subroutine attribute.

Hello, All

Thank you all for your responses. After thinking about it I decided to make a basic implementation.

package Access::Attribute; use strict; use warnings; use Attribute::Handlers; use Data::Dumper; sub UNIVERSAL::access_root : ATTR(CODE) { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; if ($< != 0) { die "Access Denied to subroutine " . *{$symbol}{NAME} . "\n"; } } sub UNIVERSAL::access_list : ATTR(CODE) { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; return if !$data; my @data = (ref $data) ? @$data : $data; my $match = 0; for my $user (@data) { my @passwd = getpwnam($user); next if !@passwd; $match = 1 if $< == $passwd[2]; } if ($match == 0) { die "Access Denied to subroutine " . *{$symbol}{NAME} . "\n"; } } 1;

This is mostly to teach myself Attributes, but I thought I would share it.

Thanks,