package Games::WebPaper::Team;

use warnings;
use strict;

=head1 NAME

Games::WebPaper::Team - Encapsulates a WebPaper Team

=cut
our $VERSION = '0.01';

=head1 Synopsis

    use Games::WebPaper::Team;

    my $team = Games::WebPaper::Team->new("3r4s3r);

=head1 Functions

=head2 new

Creates a new team. You must supply a team name. The team will have no
members, and a generated password. Returns the newly created object.

=cut

sub new {
  my ($class, $teamname) = @_;
  return undef unless defined $teamname and $teamname;
  my $self = bless({members=>[]},$class);
  $self->teamname($teamname);
  $self->_genpassword;
  $self;
}

=head2 teamname

This accessor make you able to change or obtain a team name. When
called with a parameter, will change the name of the team. Without
parameters, it will return the current team name.

=cut

sub teamname {
  my $self = shift;
  if (defined($_[0])) {
    $self->{teamname} = shift;
  }
  $self->{teamname}
}

=head2 password

This accessor make you able to access the team password (if you call
the method without parameters) or to change it.

=cut

sub _genpassword {
  my $self = shift;
  my @letters = ('A'..'Z','a'..'z',0..9);
  my $password;
  for (1..8) {
    $password.=$letters[rand(@letters)];
  }
  $self->password($password);
}

sub password {
  my $self = shift;
  if (defined($_[0])) {
    $self->{password} = shift;
  }
  $self->{password}
}

=head2 addmember

Adds a member to the team. Two parameters are obligatory: the name and
the email of the team member. Although the code does not force the
second argument to be an email, it is necessary.

=cut

sub addmember {
  my ($self, $name, $email) = @_;
  return undef unless defined $name and $name and defined $email and $email;
  push @{$self->{members}}, { name => $name, email => $email };
  return $name;
}

=head2 members

Returns a list of hashes with the members information.

=cut

sub members {
  my $self = shift;
  return @{$self->{members}}
}

=head1 Author

Alberto Simoes, C<< <ambs@cpan.org> >>

=head1 Bugs

This object really does not store the password in a cryptic way. This
is a module for games, and we hope nobody will try to hack it. Maybe
later I can add support for ciphered passwords.

Please report any bugs or feature requests to
C<bug-games-webpaper@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.  I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.

=head1 Copyright & License

Copyright 2004 Alberto Simoes, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1; # End of Games::WebPaper::Team
