home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / FileBased.pm < prev    next >
Encoding:
Perl POD Document  |  2003-11-12  |  2.0 KB  |  75 lines

  1. # Copyright (c) 1998-2003 by Jonathan Swartz. All rights reserved.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the same terms as Perl itself.
  4.  
  5. package HTML::Mason::Component::FileBased;
  6.  
  7. use strict;
  8.  
  9. use File::Basename;
  10. use File::Spec;
  11.  
  12. use HTML::Mason::Component;
  13. use base qw(HTML::Mason::Component);
  14.  
  15. use HTML::Mason::Exceptions( abbr => ['error'] );
  16.  
  17. use HTML::Mason::MethodMaker ( read_only => [ qw( path source_file name dir_path ) ] );
  18.  
  19. sub is_file_based { 1 }
  20. sub persistent { 1 }
  21. sub source_dir {
  22.     my $dir = dirname($_[0]->source_file);
  23.     return File::Spec->canonpath($dir);
  24. }
  25. sub title {
  26.     my ($self) = @_;
  27.     return $self->path . ($self->{source_root_key} ? " [".lc($self->{source_root_key})."]" : "");
  28.     #return $self->path . ($self->{source_root_key} ? " [$self->{source_root_key}]" : "");
  29. }
  30.  
  31. # Ends up setting $self->{path, source_root_key, source_file} and a few in the parent class
  32. sub assign_runtime_properties {
  33.     my ($self, $interp, $source) = @_;
  34.  
  35.     $self->{source_file} = $source->friendly_name;
  36.     $self->{source_root_key} = $source->extra->{comp_root};
  37.  
  38.     # We used to use File::Basename for this but that is broken
  39.     # because URL paths always use '/' as the dir-separator but we
  40.     # could be running on any OS.
  41.     #
  42.     # The regex itself is taken from File::Basename.
  43.     #
  44.     @{$self}{ 'dir_path', 'name'} = $source->comp_path =~ m,^(.*/)?(.*),s;
  45.     $self->{dir_path} =~ s,/$,, unless $self->{dir_path} eq '/';
  46.  
  47.     $self->SUPER::assign_runtime_properties($interp, $source);
  48. }
  49.  
  50. 1;
  51.  
  52. __END__
  53.  
  54. =head1 NAME
  55.  
  56. HTML::Mason::Component::FileBased - Mason File-Based Component Class
  57.  
  58. =head1 DESCRIPTION
  59.  
  60. This is a subclass of
  61. L<HTML::Mason::Component|HTML::Mason::Component>. Mason uses it to
  62. implement components which are stored in files.
  63.  
  64. =head1 METHODS
  65.  
  66. See L<the FILE-BASED METHODS section of
  67. HTML::Mason::Component|HTML::Mason::Component/FILE-BASED METHODS> for
  68. documentation.
  69.  
  70. =head1 SEE ALSO
  71.  
  72. L<HTML::Mason::Component|HTML::Mason::Component>
  73.  
  74. =cut
  75.