-sub prepared_print {
- my $self = shift;
- my $step = shift;
-
- my $hash_base = $self->run_hook('hash_base', $step) || {};
- my $hash_comm = $self->run_hook('hash_common', $step) || {};
- my $hash_form = $self->run_hook('hash_form', $step) || {};
- my $hash_fill = $self->run_hook('hash_fill', $step) || {};
- my $hash_swap = $self->run_hook('hash_swap', $step) || {};
- my $hash_errs = $self->run_hook('hash_errors', $step) || {};
-
- ### fix up errors
- $hash_errs->{$_} = $self->format_error($hash_errs->{$_})
- foreach keys %$hash_errs;
- $hash_errs->{'has_errors'} = 1 if scalar keys %$hash_errs;
-
- ### layer hashes together
- my $fill = {%$hash_form, %$hash_base, %$hash_comm, %$hash_fill};
- my $swap = {%$hash_form, %$hash_base, %$hash_comm, %$hash_swap, %$hash_errs};
-
- ### run the print hook - passing it the form and fill info
- $self->run_hook('print', $step, $swap, $fill);
-}
-
-sub print {
- my ($self, $step, $swap, $fill) = @_;
- my $file = $self->run_hook('file_print', $step); # get a filename relative to template_path
- my $out = $self->run_hook('swap_template', $step, $file, $swap);
- $self->run_hook('fill_template', $step, \$out, $fill);
- $self->run_hook('print_out', $step, \$out);
-}
-
-sub print_out {
- my ($self, $step, $out) = @_;
-
- $self->cgix->print_content_type($self->mimetype($step), $self->charset($step));
- print ref($out) eq 'SCALAR' ? $$out : $out;
-}
-
-sub mimetype { shift->{'mimetype'} || 'text/html' }
-sub charset { shift->{'charset'} || '' }
-
-sub swap_template {
- my ($self, $step, $file, $swap) = @_;
-
- my $args = $self->run_hook('template_args', $step);
- $args->{'INCLUDE_PATH'} ||= $args->{'include_path'} || $self->template_path;
-
- my $t = $self->template_obj($args);
- my $out = '';
- $t->process($file, $swap, \$out) || die $t->error;
-
- return $out;
-}
-
-sub template_path {
- my $self = shift;
- return $self->{'template_path'} || $self->base_dir_abs;
-}
-
-sub template_args { shift->{'template_args'} || {} }
-
-sub template_obj {
- my ($self, $args) = @_;
-
- require CGI::Ex::Template;
- my $t = CGI::Ex::Template->new($args);
-}
-
-sub fill_template {
- my ($self, $step, $outref, $fill) = @_;
-
- return if ! $fill;
-
- my $args = $self->run_hook('fill_args', $step);
- local $args->{'text'} = $outref;
- local $args->{'form'} = $fill;
-
- require CGI::Ex::Fill;
- CGI::Ex::Fill::fill($args);
-}
-
-sub fill_args { shift->{'fill_args'} || {} }
-
-sub pre_step { 0 } # success indicates we handled step (don't continue step or loop)
-sub skip { 0 } # success indicates to skip the step (and continue loop)
-sub prepare { 1 } # failure means show step
-sub finalize { 1 } # failure means show step
-sub post_print { 0 }
-sub post_step { 0 } # success indicates we handled step (don't continue step or loop)
-
-sub morph_package {
- my $self = shift;
- my $step = shift || '';
- my $cur = ref $self; # default to using self as the base for morphed modules
- my $new = $cur .'::'. $step;
- $new =~ s/(\b|_+)(\w)/\u$2/g; # turn Foo::my_step_name into Foo::MyStepName
- return $new;
-}
-
-sub name_module {
- my $self = shift;
- my $step = shift || '';
-
- return $self->{'name_module'} ||= do {
- # allow for cgi-bin/foo or cgi-bin/foo.pl to resolve to "foo"
- my $script = $self->script_name;
- $script =~ m/ (\w+) (?:\.\w+)? $/x || die "Couldn't determine module name from \"name_module\" lookup ($step)";
- $1; # return of the do
- };
-}
-
-sub name_step {
- my ($self, $step) = @_;
- return $step;
-}