Apache2-PageKit

 view release on metacpan or  search on metacpan

lib/Apache2/PageKit/Model.pm  view on Meta::CPAN

    $model->{pkit_pk}->{page_id} = $page_id;
    return;
  }

  # relative url
  my @old    = split /\/+/, $model->{pkit_pk}->{page_id};
  my @new    = split /\/+/, $page_id;
  pop @old;
  foreach (@new) {
    if ( $_ eq '..' ) { pop @old }
    elsif ( $_ ne '.' ) { push @old, $_ }
  }
  $model->{pkit_pk}->{page_id} = join '/', @old;
}

sub pkit_internal_execute_redirect {
  my ($model, $page_id) = @_;

  my $pk = $model->{pkit_pk};
  my $old_page_id = $pk->{page_id};
  $model->pkit_internal_redirect($page_id);

  if  ( $old_page_id ne $pk->{page_id} ) {

    if ( $pk->{page_session} ) {
      # save session
      delete $pk->{page_session};
    }

    # load the page session if needed
    $pk->load_page_session;
  }
  $pk->page_code;
}

# currently input_param is just a wrapper around $apr
sub input {
  my $model = shift;
  
  if ( @_ > 1 && exists $model->{pkit_input_hashref} ) {
    # insert something, we must update the hashref
    my %params = @_;
    while ( my ( $key, $value ) = each %params ) {
      $model->{pkit_input_hashref}->{$key} = $value;
    }
  }

  if(wantarray){
    # deal with multiple value containing parameters
    my @list = $model->{pkit_pk}->{apr}->param(@_);
    return @list;
  } else {
    return $model->{pkit_pk}->{apr}->param(@_);
  }
}

sub fillinform {
  my $model = shift;
  my @params = @_;
  for ( @params ) {
    Encode::_utf8_off( $_ ) unless ref $_;
  }
  return $model->{pkit_pk}->{fillinform_object}->param(@params);
}

sub ignore_fillinform_fields {
  my $model = shift;
  push @{$model->{pkit_pk}->{ignore_fillinform_fields}}, @_;
}

sub output {
  return shift->{pkit_pk}->{output_param_object}->param(@_);
}

sub pkit_status_code {
  my $pk = shift->{pkit_pk};
  my $old_status_code = $pk->{status_code};
  $pk->{status_code} = $_[0] if ( @_ );
  return $old_status_code;
}

sub output_convert {
  my ($model, %p) = @_;
  my $view = $model->{pkit_pk}->{view};
  my $input_charset = exists $p{input_charset} ? $p{input_charset} : $view->{default_input_charset};
    &_change_params($input_charset, $p{output} ? %{$p{output}} : %p );
  $model->output( $p{output} || %p );
}

sub pnotes {
  my $model = shift;
  my $apr = $model->{pkit_pk}->{apr};
  if($apr->can('pnotes')){
    $apr->pnotes(@_);
  } else {
    # if running outside of mod_perl
    return $model->{pkit_pk}->{pnotes_param_object}->param(@_);
  }
}

# put here so that it can be overriden in derived classes
sub pkit_get_default_page {
  return shift->{pkit_pk}->{config}->get_global_attr('default_page') || 'index';
}

sub create {
  my ($model, $class) = @_;
  my $create_model = $class->new(pkit_pk => $model->{pkit_pk});
  return $create_model;
}

# this is experimental and subject to change
sub dispatch {
  warn "dispatch is depreciated - use create instead";
  my ($model, $class, $method, @args) = @_;
  my $dispatch_model = $class->new(pkit_pk => $model->{pkit_pk});
#  $dispatch_model->{pkit_pk} = $model->{pkit_pk} if exists $model->{pkit_pk};
  no strict 'refs';
  return &{$class . '::' . $method}($dispatch_model, @args);
}



( run in 0.588 second using v1.01-cache-2.11-cpan-39bf76dae61 )