Apache-Voodoo

 view release on metacpan or  search on metacpan

lib/Apache/Voodoo/Install/Config.pm  view on Meta::CPAN


	my $path = $INC{"Apache/Voodoo/MyConfig.pm"} || $INC{"Apache/Voodoo/Install/Config.pm"};
	$path =~ s/Install\/Config.pm$/MyConfig\.pm/;

	open(OUT,">$path") || die "Can't write to $path: $!";

	# I had this as a print block, but it tripped up the cpan.org formatter
	print OUT "################################################################################\n";
	print OUT "#\n";
	print OUT "# Installation specific settings for Apache Voodoo are stored here.\n";
	print OUT "# Do not edit this file directly.  Use the \"voodoo-control\" command instead.\n";
	print OUT "#\n";
	print OUT "################################################################################\n";
	print OUT "package Apache::Voodoo::MyConfig;\n";
	print OUT "\n";

	print OUT '$CONFIG = '. Dumper(\%cfg).";\n";

	print OUT "\n";
	print OUT "1;\n";

lib/Apache/Voodoo/Table.pm  view on Meta::CPAN

	}
	return $self->{'table'};
}

sub success {
	my $self = shift;

	return $self->{'success'};
}

sub edit_details {
	my $self = shift;

	# if there wasn't a successful edit, then there's no details :)
	return unless $self->{'success'};

	return $self->{'edit_details'} || [];
}

sub add_details {
	my $self = shift;

	# if there wasn't a successful add, then there's no details :)
	return unless $self->{'success'};

	return $self->{'add_details'} || [];
}

lib/Apache/Voodoo/Table.pm  view on Meta::CPAN

			undef,
			$values->{$_});
		if ($res->[0]->[0] == 1) {
			$errors->{"DUP_$_"} = 1;
		}
	}

	return ($values,$errors);
}

sub validate_edit {
	my $self   = shift;
	my $p      = shift;

	my $dbh    = $p->{'dbh'};
	my $params = $p->{'params'};

	unless ($params->{$self->{'pkey'}} =~ /$self->{'pkey_regexp'}/) {
		return $self->display_error("Invalid ID");
	}

lib/Apache/Voodoo/Table.pm  view on Meta::CPAN

		my $res = $dbh->selectall_arrayref($query);

		$errors->{$_->{'fkey'}} = $self->prep_select($res,$errors->{$_->{'fkey'}} || $_->{'sdefault'});
	}

	# If we get here the user is just loading the page
	# for the first time or had errors.
	return $errors;
}

sub edit {
	my $self = shift;
	my $p    = shift;
	my $additional_constraint = shift;

	$self->{'success'} = 0;
	$self->{'edit_details'} = [];

	my $dbh    = $p->{'dbh'};
	my $params = $p->{'params'};

	# make sure our additional constraint won't break the sql
	$additional_constraint =~ s/^\s*(where|and|or)\s+//go;
	if (length($additional_constraint)) {
		$additional_constraint = "AND $additional_constraint";
	}

lib/Apache/Voodoo/Table.pm  view on Meta::CPAN

		return $self->display_error("No record with that ID found");
	}

	my %original_values;
	for (my $i=0; $i <= $#{$self->{'columns'}}; $i++) {
		$original_values{$self->{'columns'}->[$i]} = $res->[0]->[$i];
	}

	my $errors = {};
	if ($params->{'cm'} eq "update") {
		my ($values,$errors) = $self->validate_edit($p);

		if (scalar keys %{$errors}) {
			$errors->{'has_errors'} = 1;

			# copy values into template
			$errors->{$self->{'pkey'}} = $params->{$self->{'pkey'}};
			foreach (keys(%{$values})) {
				$errors->{$_} = $values->{$_};
			}
		}
		else {
			# copy clean dates,times into params for insertion
			foreach (@{$self->{'dates'}},@{$self->{'times'}}) {
				$values->{$_->{'name'}} = $values->{$_->{'name'}."_CLEAN"};
			}

			# let's figure out what they changed so caller can do something with that info if they want
			foreach (@{$self->{'columns'}}) {
				if ($values->{$_} ne $original_values{$_}) {
					push(@{$self->{'edit_details'}},[$_,$original_values{$_},$values->{$_}]);
				}
			}
			my $update_statement = "
				UPDATE
					$self->{'table'}
				SET ".
					join("=?,",@{$self->{'columns'}})."=?
				WHERE
					$self->{'pkey'} = ?
				$additional_constraint";

lib/Apache/Voodoo/Table/Probe/MySQL.pm  view on Meta::CPAN

		$type =~ s/[,\d\(\) ]+/_/g;
		$type =~ s/_$//g;

		if ($self->can($type)) {
			$self->$type(\%column,$size);
		}
		else {
			push(@{$data{'ERRORS'}},"unsupported type $row->[1]");
		}

		# is this param required for add / edit (does the column allow nulls)
		$column{'required'} = 1 unless $row->[2] eq "YES";

		if ($row->[3] eq "PRI") {
			# primary key.  NOTE THAT CLUSTERED PRIMARY KEYS ARE NOT SUPPORTED
			$data{'primary_key'} = $name;

			# is the primary key user supplied
			unless ($row->[5] eq "auto_increment") {
				$data{'pkey_user_supplied'} = 1;
			}



( run in 0.513 second using v1.01-cache-2.11-cpan-de7293f3b23 )