package ProjectCreate; =head1 NAME ProjectCreate -- Creates a new project =head1 SYNOPSIS ProjectCreate -> new($configuration, $db_manager, $project); =head1 DESCRIPTION This package creates a new project for extropy. ProjectCreate, itself, is not an object and cannot be instantiated. =head1 VERSION 0.001 (last update: 3/8/04) =head1 AUTHOR Chet Langin, clangin@siu.edu SIU Plant Biotechnology and Genomics Core-facility =head1 BUGS The module is under development and is not yet finished. =head1 SEE ALSO extropy =head1 COPYRIGHT Copyright 2004, Chet Langin, All Rights Reserved. This program is free software. You may copy or redistribute it under the same terms as Perl itself. =head1 METHODS The remainder of this document describes the methods available to the programmer. =cut # load the pragmas use warnings; use strict; # load other modules use ExtropyConstants; use ExtropyUtils; =head2 new() ProjectCreate->new($configuration, $db_manager, $project); Uses dialog boxes to create a new instance of a Project object. =cut # package variables # ******************************** new ****************************** sub new { my $self = shift; # self is ProjectCreate my $configuration = shift; my $db_manager = shift; my $project = shift; my $project_name = ""; my $project_obtained = TRUE; my $loop = TRUE; while($loop) { message_start; message("Name your project. The database name will be the same name"); message("as your project."); blank_line; $project_name = prompt("Enter a new project name"); if($project_name eq "Q") { $loop = FALSE; $project_obtained = FALSE; } # if elsif(project_name_ok($project_name, $configuration, $db_manager)) { $loop = FALSE; $project_obtained = TRUE; if($db_manager->{reset}) { $project->reset; $db_manager->{reset} = FALSE; } # if } # elsif else { $project_obtained = FALSE; if(!yes("Try another project name?")) { $loop = FALSE; } # if } # else } # while if($project_obtained) { my $exists = FALSE; foreach my $each_project (@{$configuration->{project_array}}) { $exists = TRUE if($each_project eq $project_name); } # foreach if(!$exists) { push (@{$configuration->{project_array}}, $project_name); } # if $project->{current_project} = $project_name; # save the configuration $configuration->save($project); TRUE; } # if else { FALSE; } # else } # new # ******************************** project_name_ok ****************************** =head2 project_name_ok my $boolean = ProjectCreate->project_name_ok($project_name, $configuration, $db_manager); Determines if a project name is acceptable. For internal usage only. =cut # --------------------------------------------------------------------------------- sub project_name_ok { my $project_name = shift; my $configuration = shift; my $db_manager = shift; my $name_ok = TRUE; # see if the project name is an empty string if($project_name !~ /^[a-zA-Z]{1,20}$/) { message_start; message("The project name must be from 1 to 20 alpha characters"); $name_ok = FALSE; } # if else { # see if this project already exists my $exists = FALSE; foreach my $each_project (@{$configuration->{project_array}}) { $exists = TRUE if($each_project eq $project_name); } # foreach if($exists) { message_start; message("Project $project_name already exists."); $name_ok = FALSE if(!yes("Use the existing $project_name Project?")); } # if # see if a database already exists with this project name if($name_ok) { if (!$db_manager->get_username($project_name)) { $name_ok = FALSE; } # if } # if } # else if($name_ok) { return TRUE; } # if else { return FALSE; } # else } # project_name_ok 1