| 1 | # Copyright (c) 1998-2005 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::Resolver::File; | ||||||||||||||||||||||||||||
| 6 | 33 | $HTML::Mason::Resolver::File::VERSION = '1.58'; | |||||||||||||||||||||||||||
| 7 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 33 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 33 | ▶ | use File::Glob; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 33 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 33 | ▶ | use HTML::Mason::Tools qw(read_file_ref paths_eq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 33 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 33 | ▶ | use HTML::Mason::ComponentSource; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 33 | ▶ | use HTML::Mason::Resolver; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 33 | ▶ | use base qw(HTML::Mason::Resolver); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 33 | ▶ | use HTML::Mason::Exceptions (abbr => ['param_error']); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub get_info { | ||||||||||||||||||||||||||||
| 24 | 2394 | ▶ | my ($self, $path, $comp_root_key, $comp_root_path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_info: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Note that canonpath has the property of not collapsing a series | ||||||||||||||||||||||||||||
| 27 | # of /../../ dirs in an unsafe way. This means that if the | ||||||||||||||||||||||||||||
| 28 | # component path is /../../../../etc/passwd, we're still safe. I | ||||||||||||||||||||||||||||
| 29 | # don't know if this was intentional, but it's certainly a good | ||||||||||||||||||||||||||||
| 30 | # thing, and something we want to preserve if the code ever | ||||||||||||||||||||||||||||
| 31 | # changes. | ||||||||||||||||||||||||||||
| 32 | 2394 | my $srcfile = File::Spec->canonpath( File::Spec->catfile( $comp_root_path, $path ) ); | |||||||||||||||||||||||||||
| 33 | 2394 | ▶ | return unless -f $srcfile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 1195 | my $modified = (stat _)[9]; | |||||||||||||||||||||||||||
| 35 | 1195 | ▶ | my $base = $comp_root_key eq 'MAIN' ? '' : "/$comp_root_key"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1195 | ▶ | $comp_root_key = undef if $comp_root_key eq 'MAIN'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | return | ||||||||||||||||||||||||||||
| 39 | HTML::Mason::ComponentSource->new | ||||||||||||||||||||||||||||
| 40 | ( friendly_name => $srcfile, | ||||||||||||||||||||||||||||
| 41 | comp_id => "$base$path", | ||||||||||||||||||||||||||||
| 42 | last_modified => $modified, | ||||||||||||||||||||||||||||
| 43 | comp_path => $path, | ||||||||||||||||||||||||||||
| 44 | comp_class => 'HTML::Mason::Component::FileBased', | ||||||||||||||||||||||||||||
| 45 | extra => { comp_root => $comp_root_key }, | ||||||||||||||||||||||||||||
| 46 | 571 | ▶ | source_callback => sub { read_file_ref($srcfile) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 1195 | ); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||
| 51 | # Return all existing url_paths matching the given glob pattern underneath the given root. | ||||||||||||||||||||||||||||
| 52 | # glob_path is required for using the "preloads" parameter. | ||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||
| 54 | sub glob_path { | ||||||||||||||||||||||||||||
| 55 | 3 | ▶ | my ($self, $pattern, $comp_root_path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
glob_path: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | my @files = File::Glob::bsd_glob($comp_root_path . $pattern); | |||||||||||||||||||||||||||
| 58 | 3 | my $root_length = length $comp_root_path; | |||||||||||||||||||||||||||
| 59 | 3 | my @paths; | |||||||||||||||||||||||||||
| 60 | 3 | foreach my $file (@files) { | |||||||||||||||||||||||||||
| 61 | 7 | ▶ | next unless -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | if (substr($file, 0, $root_length) eq $comp_root_path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 6 | push(@paths, substr($file, $root_length)); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 3 | return @paths; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||
| 70 | # Given an apache request object and a list of component root pairs, | ||||||||||||||||||||||||||||
| 71 | # return the associated component path or undef if none exists. This | ||||||||||||||||||||||||||||
| 72 | # is called for top-level web requests that resolve to a particular | ||||||||||||||||||||||||||||
| 73 | # file. | ||||||||||||||||||||||||||||
| 74 | # apache_request_to_comp_path is required for running Mason under mod_perl. | ||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||
| 76 | sub apache_request_to_comp_path { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my ($self, $r, @comp_root_array) = @_; | ||||||||||||||||||||||||||
|
Subroutine
apache_request_to_comp_path: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $file = $r->filename; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | $file .= $r->path_info unless -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # Clear up any weirdness here so that paths_eq compares two | ||||||||||||||||||||||||||||
| 83 | # 'canonical' paths (canonpath is called on comp roots when | ||||||||||||||||||||||||||||
| 84 | # resolver object is created. Seems to be needed on Win32 (see | ||||||||||||||||||||||||||||
| 85 | # bug #356). | ||||||||||||||||||||||||||||
| 86 | 0 | $file = File::Spec->canonpath($file); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | foreach my $root (map $_->[1], @comp_root_array) { | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (paths_eq($root, substr($file, 0, length($root)))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | my $path = substr($file, length $root); | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | $path = length $path ? join '/', File::Spec->splitdir($path) : '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | chop $path if $path ne '/' && substr($path, -1) eq '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$path ne "/" and substr($path, -1) eq "/"
MC/DC0%0/2
$path ne "/" and substr($path, -1) eq "/"
$path ne "/"
substr($path, -1) eq "/"
Truth table0%0/3
A and B
A= $path ne "/"B= substr($path, -1) eq "/"
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | return $path; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 33 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||