Apache-Scriptor

 view release on metacpan or  search on metacpan

Scriptor.pm  view on Meta::CPAN

}

# void removehandler(ext1, ext2, ...)
# Óäàëÿåò îáðàáîò÷èê(è) äëÿ ðàñøèðåíèé ext1 è ext2.
sub removehandler
{ my ($this,@ext)=@_;
  foreach (@ext) { delete $this->{Handlers}{$_} }
  return;
}

# void set_404_url($url)
# Óñòàíàâëèâàåò àäðåñ ñòðàíèöû 404-é îøèáêè, íà êîòîðóþ áóäåò ïðîèçâåäåí 
# ðåäèðåêò, åñëè ôàéë íå íàéäåí.
sub set_404_url
{ my ($th,$url)=@_;
  $th->{404}=$url;
}

# void set_htaccess_name($name)
# Óñòàíàâëèâàåò èìÿ htaccess-ôàéëà. Ïî óìîë÷àíèþ ýòî .htaccess.
sub set_htaccess_name
{ my ($th,$htaccess)=@_;
  $th->{htaccess}=$htaccess;
}

sub process_htaccess

Scriptor.pm  view on Meta::CPAN

  while(!eof(F)) {
    my $s=<F>; $s=~s/^\s+|#.*|\s+$//sg; next if $s eq "";
    # Äèðåêòèâà Action
    if($s=~m/Action\s+([\w\d-]+)\s*"?([^"]+)"?/si) {
      $Action{$1}=1 if $2 eq $th->{self_scriptname};
    }
    # Äèðåêòèâà AddHandler
    if($s=~m/AddHandler\s+([\w\d-]+)\s*(.+)/si) {
      push @AddHandler, [ $1, [ map { s/^\s*\.?|\s+$//sg; $_?($_):() } split /\s+/, $2 ] ];
    }
    # Äèðåêòèâà ErrorDocument 404
    if($s=~/ErrorDocument\s+404\s+"?([^"]+)"?/si) {
      $th->set_404_url($1);
    }
  }
  # Çàòåì äîáàâëÿåì öåïî÷êè îáðàáîò÷èêîâ
  my %ProcessedExt=();
  foreach my $info (@AddHandler) {
    my ($hand,$ext)=@$info;
    # Ñðàçó îòìåòàåì îáðàáîò÷èêè, êîòîðûå ÍÅ óêàçûâàþò íà Apache::Scriptor.
    # Ìû íå ìîãëè ýòîãî ñäåëàòü â âåðõíåì öèêëå, ïîòîïìó ÷òî äèðåêòèâû
    # Action è AddHandler ìîãóò èäòè íå ïî ïîðÿäêó.
    next if !$Action{$hand};

Scriptor.pm  view on Meta::CPAN

# ðàáîòàåò ïðàâèëüíî - íàïðèìåð, òàêàÿ øòóêà íå ïðîéäåò, åñëè äèðåêòîðèÿ áûëà
# çàâåäåíà êàê Alias Apache).
sub run_uri
{ my ($this,$uri,$path)=@_;
  Header("X-Powered-by: Apache::Scriptor v$VERSION. (C) Dmitry Koterov <koterov at cpan dot org>") if !$CopySend++;

  # Òåïåðü ðàáîòàåì ñ ÊÎÏÈÅÉ îáúåêòà. Òàêèì îáðàçîì, äàëüíåéøèå âûçîâû
  # process_htaccesses è ò.ä. íå îòðàçÿòñÿ íà îáùåì ñîñòîÿíèè îáúåêòà
  # ïîñëå îêîí÷àíèÿ çàïðîñà.
  local $this->{Handlers}={%{$this->{Handlers}}};
  local $this->{404}=$this->{404};

  # Ðàçäåëÿåì íà URL è QUERY_STRING
  local ($ENV{SCRIPT_NAME},$q) = split /\?/, $uri, 2;
  $ENV{QUERY_STRING}=defined $q? $q : "";

  # Âû÷èñëÿåì ïóòü ê ôàéëó ñêðèïòà ïî URI
  if(!$path) {
    $path="$ENV{DOCUMENT_ROOT}$ENV{SCRIPT_NAME}";
  }

Scriptor.pm  view on Meta::CPAN

      }
      # ïîëó÷àåì óêàçàòåëü íà ôóíêöèþ îáðàáîò÷èêà
      local $this=$th;
      $func=*{$func}{CODE};
    }
    # Ôóíêöèÿ îáðàáîò÷èêà ïðèíèìàåò ïàðàìåòð: âõîäíîé áóôåð.
    # Åå çàäà÷à - îáðàáîòàòü åãî è, èñïîëüçóÿ print, ïðîïå÷àòàòü ðåçóëüòàò.
    #  ñëó÷àå îøèáêè (ôàéë íå íàéäåí) ôóíêöèÿ äîëæíà âîçâðàòèòü -1!
    my $result=&$func($input);
    if($result eq "-1") {
      if($th->{404} && $th->{404} ne $th->{self_scriptname}) {
        Redirect($th->{404});
        exit;
      } else {
        die "$hand: could not find the file $ENV{SCRIPT_FILENAME}\n";
      }
    }

    # Òî, ÷òî ïîëó÷èëîñü, êëàäåì âî âõîäíîé áóôåð äëÿ ñëåäóþùåãî îáðàáîò÷èêà.
    # Åñëè âûâîä íå ïåðåíàïðàâëÿëñÿ, òî êëàäåì òóäà "".
    $input=$OutObj?$OutObj->buf:"";
  }

Scriptor.pm  view on Meta::CPAN

=item *

Uses ONLY perl binary.

=item *

Helps to organize the Apache handler conveyor. That means you can redirect the output from one handler to another handler.

=item *

Supports non-existance URL handling and 404 Error processing.

=item *

Uses C<.htaccess> files to configure.

=back


=head1 EXAMPLE

Scriptor.pm  view on Meta::CPAN

late-loadable function names (as while parsing the C<.htaccess> file).

=item C<$obj'pushhandler($ext, $handler)>

Adds the handler C<$handler> th the end of the conveyor for extension C<$ext>.

=item C<$obj'removehandler($ext)>

Removes all the handlers for extension C<$ext>.

=item C<$obj'set_404_url($url)>

Sets up the redirect address for 404 error. By default, this value is 
bringing up from C<.htaccess> files.

=item C<$obj'set_htaccess_name($name)>

Tells Apache::Scriptor object then Apache user configuration file is called C<$name>
(by default C<$name=".htaccess">).

=item C<$obj'process_htaccess($filename)>

Processes all the directives in the C<.htaccess> file C<$filename> and adds



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