Apache-Htgroup

 view release on metacpan or  search on metacpan

lib/Apache/Htgroup.pm  view on Meta::CPAN


Writes the current contents of the htgroup object back to the
file. If you provide a $file argument, C<save> will attempt to
write to that location.

=cut

sub save {
    my $self = shift;
    my $file = shift || $self->{groupfile};
    my $out;
    my @members;

    open( FILE, ">$file" ) || die ("Was unable to open $file for writing: $!");

    foreach my $group( keys %{ $self->{groups} } ) {

        # Work around the fact that Apache can't handle lines
        # over 8K.
        @members = keys %{ $self->{groups}->{$group} };
      if(!@members) {
              print FILE "${group}: \n";
      }
        while (@members) {
            $out = "$group:";
            while (@members) {
                $out .= " " . shift (@members);
                last if 7500 < length($out);
            }
            print FILE $out, "\n";
        }
    }
    close FILE;

    return (1);
} # }}}

# sub ismember {{{

=head2 ismember

    $foo = $htgroup->ismember($user, $group);

Returns true if the username is in the group, false otherwise

=cut
sub ismember {
    my $self = shift;
    my ( $user, $group ) = @_;

    return ( $self->{groups}->{$group}->{$user} ) ? 1 : 0;
} # }}}

1;

# Documentation {{{

=head1 Internals

Although this was not the case in earlier versions, the internal
data structure of the object looks something like the following:

 $obj = { groupfile => '/path/to/groupfile',
          groups => { group1 => { 'user1' => 1,
                                  'user2' => 1, 
                                  'user3' => 1
                                },
                      group2 => { 'usera' => 1,
                                  'userb' => 1, 
                                  'userc' => 1
                                },
                    }
        };

Note that this data structure is subject to change in the future,
and is provided mostly so that I can remember what the heck I was
thinking when I next have to look at this code.

=head1 Adding groups

A number of folks have asked for a method to add a new group. This
is unnecessary. To add a new group, just start adding users to 
a new group, and the new group will magically spring into existance.

=head1 AUTHOR

Rich Bowen, rbowen@rcbowen.com

=head1 COPYRIGHT

Copyright (c) 2001 Rich Bowen. All rights reserved.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut 

# }}}



( run in 2.210 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )