diff options
author | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-03-18 13:06:24 -0700 |
---|---|---|
committer | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-03-18 13:06:24 -0700 |
commit | 0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18 (patch) | |
tree | b868e49eaba3592a9a26fd51aaa11c78ea127cb9 /usr/src/libpiny/lib/Piny/User.pm | |
parent | 46f08c97433ed083bb479b00637c6aa5cb7b24d3 (diff) | |
download | piny-code-0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18.tar.gz piny-code-0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18.zip |
Add methods for managing group membership, and some more constraints.
Diffstat (limited to 'usr/src/libpiny/lib/Piny/User.pm')
-rw-r--r-- | usr/src/libpiny/lib/Piny/User.pm | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/usr/src/libpiny/lib/Piny/User.pm b/usr/src/libpiny/lib/Piny/User.pm index 53e310b..e4b865c 100644 --- a/usr/src/libpiny/lib/Piny/User.pm +++ b/usr/src/libpiny/lib/Piny/User.pm @@ -4,10 +4,19 @@ package Piny::User; use Moose; +use Moose::Util::TypeConstraints; use Piny::Email; use Piny::Group; +# Types + +subtype 'Username' + => as 'Str' + => where { $_ =~ /^(?!(git|ikiwiki)-)[[a-zA-Z0-9][a-zA-Z0-9_.-]*$/ } + => message { 'That username is not in the correct format for a piny user.' } + ; + # Attributes has 'uid' => @@ -18,7 +27,7 @@ has 'uid' => has 'username' => ( is => 'ro' - , isa => 'Str' + , isa => 'Username' , lazy_build => 1 ); @@ -50,6 +59,24 @@ has 'groups' => , init_arg => undef ); +# Public methods + +sub add_group { + my ( $s, @groups ) = @_; + + foreach my $group ( @groups ) { + $group->add_member( $s ); + }; +}; + +sub remove_group { + my ( $s, @groups ) = @_; + + foreach my $group ( @groups ) { + $group->remove_member( $s ); + }; +}; + # Builder methods # If constructed with just one argument, then |