Apache-SdnFw

 view release on metacpan or  search on metacpan

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

		return;
	}
}

sub tt {

=head2 tt

 $s->tt($fname,$args,[$string])

$fname can be a path to a file, or a string reference, $args is a hash ref with
values of information that is passed to template toolkit.  $string can be a 
reference to a string variable, or to an array ref, in which case the results
are pushed into that array.  If $string is not defined, then the results are
appended to $s->{content}.

 $s->tt('object/template.tt', { s => $s, hash => \%hash });
 $s->tt('object/template.tt', { s => $s, list => \@list },\$output);
 $s->tt(\$template, { s => $s },\@output);

=cut

	my $s = shift;
	my $fname = shift;
	my $args = shift;
	my $string = shift;

	#my $agentfname;
	#if ($s->{agent}) {
	#	($fname = $agentfname) =~ s/([^\/]+\.tt)$/$s->{agent}\/$1/;
	#}

	$fname .= '.xml' if ($s->{api});

	if (defined $string) {
		if (ref $string eq 'ARRAY') {
			my $tmp;
			$s->{tt}->process($fname,$args,\$tmp) || croak $s->{tt}->error();
			push @{$string}, $tmp;
		} else {
			$s->{tt}->process($fname,$args,$string) || croak $s->{tt}->error();
		}
	} else {
		$s->{tt}->process($fname,$args) || croak $s->{tt}->error();
	}

}

=head2 update_and_log

 $s->update_and_log(
 	table => tablename,
	idfield => idfield,
	object => object,
	id => id,
	existing => \%hash,
	update => \%hash);

=cut 

sub update_and_log {
	my $s = shift;
	my %args = @_;

	croak "Missing table" unless($args{table});
	croak "Missing idfield" unless($args{idfield});
	croak "Missing object" unless($args{object});
	croak "Missing id" unless($args{id});
	croak "Missing existing" unless(defined($args{existing}));
	croak "Missing update" unless(defined($args{update}));

	#croak "<pre>".Data::Dumper->Dump([\%{$args{update}}])."</pre>";
	my %update;
	foreach my $k (keys %{$args{update}}) {
		if (exists($args{existing}{$k})) {
			my $object;
			if ($args{update}{$k} =~ m/^(.+):(\d*)$/) {
				$object = $1;
				$args{update}{$k} = $2;
			}

			if ($args{update}{$k} ne $args{existing}{$k}) {
				$update{$k} = $args{update}{$k};
				my $old = $args{existing}{$k};
				my $new = $update{$k};
				my $field = $k;
				if ($object) {
					$field = $object;
					$old = $s->db_q("SELECT name
						FROM ${object}s_v_keyval
						WHERE id=?
						",'scalar',
						v => [ $args{existing}{$k} ])
						if ($args{existing}{$k});

					$new = $s->db_q("SELECT name
						FROM ${object}s_v_keyval
						WHERE id=?
						",'scalar',
						v => [ $update{$k} ])
						if ($update{$k});
				}

				$s->log($args{object},$args{id},
					"$args{object} $field changed from [$old] to [$new]");
			}
		} else {
			croak "Existing data for $args{object} field $k not defined";
		}
	}

	#croak "<pre>".Data::Dumper->Dump([\%update])."</pre>";
	if (keys %update) {
		$s->db_update_key($args{table},$args{idfield},$args{id},\%update);
	}
}

sub in_to_hash {

=head2 in_to_hash

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.537 second using v1.00-cache-2.02-grep-82fe00e-cpan-1310916c57ae )