HTML-Bricks

 view release on metacpan or  search on metacpan

lib/HTML/Bricks/Mappings.pm  view on Meta::CPAN


  open($fh,"< $filename");

  return undef if !defined $fh;

  my $string = join('',<$fh>);

  my $VAR1;
  
  eval($string);

  close($fh);

  $self->{cached_mtime} = $statdata[9];
  $self->{cached_rary} = $VAR1;

  return $VAR1;  # reference to an array
}

#-----------------------------------------------------------------------------
# write_mappings
#-----------------------------------------------------------------------------
sub write_mappings($$) {
  
  my ($self,$rary) = @_;

  use Apache::File;
  my $fh = Apache::gensym();

  my $filename = $self->{basename};
  open($fh,"> $filename");

  return if !defined $fh;

  use Data::Dumper;
  print $fh Dumper($rary);

  close($fh);
}

#-----------------------------------------------------------------------------
# insert
#-----------------------------------------------------------------------------
sub insert($$$) {

  my ($self,$position,$rmapping) = @_;
  
  my $rary = $self->read_mappings();

  $position = $#$rary+1 if $position == -1;

  splice @$rary, $position, 0, $rmapping;

  $self->write_mappings($rary);

}

#-----------------------------------------------------------------------------
# update
#-----------------------------------------------------------------------------
sub update($$$) {
  my ($self, $position, $rmapping) = @_;

  $position = 0 if !defined $position;
  my $rary = $self->read_mappings();
  splice @$rary, $position, 1, $rmapping;
  $self->write_mappings($rary);

}

#-----------------------------------------------------------------------------
# [] get_list
#-----------------------------------------------------------------------------
sub get_list($) {

  my $self = shift;

  my $rary = $self->read_mappings;

  return undef if !defined $rary;

  my @ary = @$rary;  # return a copy
  return \@ary;

}

#-----------------------------------------------------------------------------
# delete
#-----------------------------------------------------------------------------
sub delete($$) {
  my ($self,$position) = @_;

  my $rary = $self->read_mappings();

  splice @$rary, $position, 1;

  $self->write_mappings($rary);
}

#-----------------------------------------------------------------------------
# [] get_matches
#-----------------------------------------------------------------------------
sub get_matches($) {
  my ($self,$uri) = @_;

  my @matches;

  my $rmappings = $self->get_list();

  splice (@$rmappings, 0, 0, @hardwired_mappings); 

  foreach (@$rmappings) {

    # 1. does the beginning of the uri match the folder name?
    #    if not, next
    
    if (substr($uri,0,length($$_{folder})) ne $$_{folder}) {
      next;
    }

    # 2. does the uri have additional dirs and is the map set for recurse?



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