summaryrefslogtreecommitdiff
path: root/usr/src/libpiny/lib/Piny/Group.pm
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2010-10-29 19:46:24 -0500
committerBryan Bishop <kanzure@gmail.com>2010-10-29 19:46:24 -0500
commit7786ce2a332b0eba4b3ca7c57f906a32e8715da3 (patch)
tree5a9fe32b69a93f41ae2ac82a50788fe50c0d86fb /usr/src/libpiny/lib/Piny/Group.pm
parent413373be9ab30eb21b564cdc180cb2dcda77bfeb (diff)
downloadpiny-code-7786ce2a332b0eba4b3ca7c57f906a32e8715da3.tar.gz
piny-code-7786ce2a332b0eba4b3ca7c57f906a32e8715da3.zip
Starting repo cleanup to make this not so awful
Diffstat (limited to 'usr/src/libpiny/lib/Piny/Group.pm')
-rw-r--r--usr/src/libpiny/lib/Piny/Group.pm136
1 files changed, 0 insertions, 136 deletions
diff --git a/usr/src/libpiny/lib/Piny/Group.pm b/usr/src/libpiny/lib/Piny/Group.pm
deleted file mode 100644
index 86a6d95..0000000
--- a/usr/src/libpiny/lib/Piny/Group.pm
+++ /dev/null
@@ -1,136 +0,0 @@
-# Copyright © 2010 Julian Blake Kongslie <jblake@omgwallhack.org>
-# Licensed under the BSD 3-clause license.
-
-use strict;
-use warnings;
-
-package Piny::Group;
-
-use Moose;
-use MooseX::StrictConstructor;
-
-use Piny::User;
-
-# Attributes
-
-has 'gid' =>
- ( is => 'ro'
- , isa => 'Int'
- , lazy_build => 1
- );
-
-has 'name' =>
- ( is => 'ro'
- , isa => 'Str'
- , lazy_build => 1
- );
-
-has 'grent' =>
- ( is => 'ro'
- , isa => 'ArrayRef'
- , lazy_build => 1
- , init_arg => undef
- );
-
-has 'members' =>
- ( is => 'ro'
- , isa => 'ArrayRef[Piny::User]'
- , lazy_build => 1
- , init_arg => undef
- );
-
-# Public methods
-
-sub add_member {
- my ( $s, @users ) = @_;
-
- foreach my $user ( @users ) {
- system( "/usr/sbin/adduser", $user->name( ), $s->name( ) );
- $user->clear_groups( );
- };
-
- $s->clear_members( );
-};
-
-sub remove_member {
- my ( $s, @users ) = @_;
-
- foreach my $user ( @users ) {
- system( "/usr/sbin/deluser", $user->name( ), $s->name( ) );
- $user->clear_groups( );
- };
-
- $s->clear_members( );
-};
-
-# Builder methods
-
-# If constructed with just one argument, then
-# * If that argument is numeric, treat it as a GID.
-# * Otherwise, treat it as a name.
-around BUILDARGS => sub {
- my ( $orig, $class ) = ( shift, shift );
-
- if ( @_ == 1 && ! ref $_[0] ) {
- if ( $_[0] =~ m/^\d+$/ ) {
- return $class->$orig( gid => $_[0] );
- } else {
- return $class->$orig( name => $_[0] );
- };
- } else {
- return $class->$orig( @_ );
- };
-};
-
-sub BUILD {
- my ( $s ) = @_;
-
- if ( not ( $s->has_gid( ) or $s->has_name( ) ) ) {
- die "You must provide either GID or name!";
- };
-
- if ( $s->has_gid( ) and $s->has_name( ) ) {
- die "You must not provide both GID and name!";
- };
-};
-
-sub _build_gid {
- my ( $s ) = @_;
-
- return $s->grent( )->[2];
-};
-
-sub _build_name {
- my ( $s ) = @_;
-
- return $s->grent( )->[0];
-};
-
-sub _build_grent {
- my ( $s ) = @_;
-
- if ( $s->has_gid( ) ) {
- my @res = getgrgid( $s->gid( ) );
- die "getgrgid( " . $s->gid( ) . " ) failed: $!" unless @res;
- return \@res;
- } elsif ( $s->has_name( ) ) {
- my @res = getgrnam( $s->name( ) );
- die "getgrnam( " . $s->name( ) . " ) failed: $!" unless @res;
- return \@res;
- } else {
- die "Not enough information provided to lookup group!";
- };
-};
-
-sub _build_members {
- my ( $s ) = @_;
-
- return [ ] if ( $s->grent( )->[3] eq "" );
- return [ map { Piny::User->new( name => $_ ) } split( /:/, $s->grent( )->[3] ) ];
-};
-
-# Moose boilerplate
-
-__PACKAGE__->meta->make_immutable;
-
-1;