| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (c) 2003-4 Timothy Appnel |
|
2
|
|
|
|
|
|
|
# http://www.timaoutloud.org/ |
|
3
|
|
|
|
|
|
|
# This code is released under the Artistic License. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# Text::BIP -- Blosxom Infrastructure Package. An object-oriented module for facilitating event-based file system indexing. |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Text::BIP; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1481
|
use DirHandle; |
|
|
1
|
|
|
|
|
3029
|
|
|
|
1
|
|
|
|
|
28
|
|
|
11
|
1
|
|
|
1
|
|
8
|
use File::Spec; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
1296
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.51'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $path_delim=File::Spec->catfile('',''); # stupid hack, but it works. better way??? |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
19
|
0
|
|
|
|
|
|
my $self = bless { }, $class; |
|
20
|
0
|
|
|
|
|
|
$self->init(@_); |
|
21
|
0
|
|
|
|
|
|
return $self; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init { |
|
25
|
0
|
|
|
0
|
1
|
|
$_[0]->{__index_depth} = 0; |
|
26
|
0
|
|
0
|
|
|
|
$_[0]->{__base} = $_[1] ->{base} || '.'; |
|
27
|
0
|
|
0
|
|
|
|
$_[0]->{__depth} = $_[1]->{depth} || 0; |
|
28
|
0
|
|
|
|
|
|
$_[0]->{__stash} = undef; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
0
|
1
|
|
sub depth { $_[0]->{__depth}=$_[1] if $_[1]; $_[0]->{__depth}; } |
|
|
0
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
0
|
1
|
|
sub base { $_[0]->{__base}=$_[1] if $_[1]; $_[0]->{__base}; } |
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub stash { |
|
34
|
0
|
0
|
|
0
|
1
|
|
$_[0]->{__stash}->{ $_[1] } = $_[2] if $_[2]; |
|
35
|
0
|
|
|
|
|
|
$_[0]->{__stash}->{ $_[1] }; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# handler methods |
|
39
|
0
|
|
|
0
|
0
|
|
sub clear_handlers { $_[0]->{__handlers} = undef; } # wipes out handler hashes. |
|
40
|
0
|
0
|
|
0
|
1
|
|
sub prerun { shift->{__handlers}->{prerun}=shift if @_; } |
|
41
|
0
|
0
|
|
0
|
1
|
|
sub postrun { shift->{__handlers}->{postrun}=shift if @_; } |
|
42
|
|
|
|
|
|
|
sub file_handler { |
|
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
44
|
0
|
|
|
|
|
|
my $ref = shift; |
|
45
|
0
|
|
|
|
|
|
foreach my $ext ( @_ ) { $self->{__handlers}->{'file'}->{$ext}=$ref; } |
|
|
0
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
sub index_handler { |
|
48
|
0
|
|
|
0
|
1
|
|
my($self,$ref) = @_; |
|
49
|
0
|
|
|
|
|
|
$self->{__handlers}->{'index'}->{'*'}=$ref; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
sub read_handler { |
|
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
53
|
0
|
|
|
|
|
|
my $ref = shift; |
|
54
|
0
|
|
|
|
|
|
foreach my $ext ( @_ ) { $self->{__handlers}->{'read'}->{$ext}=$ref; } |
|
|
0
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub index { |
|
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
59
|
0
|
|
0
|
|
|
|
my $path = shift || $self->base() || '.'; |
|
60
|
0
|
0
|
|
|
|
|
if ($path) { |
|
61
|
0
|
0
|
|
|
|
|
$self->{__handlers}->{prerun}->($self) |
|
62
|
|
|
|
|
|
|
if ( defined($self->{__handlers}->{prerun}) ); |
|
63
|
0
|
|
|
|
|
|
$self->{__index_depth}=1; |
|
64
|
0
|
|
|
|
|
|
_process_dir($self,$path); |
|
65
|
0
|
|
|
|
|
|
$self->{__index_depth}=0; |
|
66
|
0
|
0
|
|
|
|
|
$self->{__handlers}->{postrun}->($self) |
|
67
|
|
|
|
|
|
|
if ( defined($self->{__handlers}->{postrun}) ); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _process_dir { |
|
72
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
73
|
0
|
|
|
|
|
|
my $path = shift; |
|
74
|
0
|
|
|
|
|
|
my $d = DirHandle->new($path); |
|
75
|
0
|
|
|
|
|
|
my $exts = $self->{exts}; |
|
76
|
0
|
|
|
|
|
|
for my $file ($d->read()) { |
|
77
|
0
|
0
|
|
|
|
|
unless ($file=~/^\./) { |
|
78
|
0
|
|
|
|
|
|
my $path_file=File::Spec->catfile($path,$file); |
|
79
|
0
|
|
|
|
|
|
$file=~m/\.([^.]*)$/; |
|
80
|
0
|
|
0
|
|
|
|
my $ext = $1 || ''; |
|
81
|
0
|
|
|
|
|
|
my %data = ( path=>$path, file=>$file, ext=>$ext ); |
|
82
|
0
|
|
|
|
|
|
push(@{ $self->{__stack} }, \%data ); |
|
|
0
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ( -f $path_file) { # all files hook? |
|
|
|
0
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ( defined( $self->{__handlers}->{file}->{ $ext } ) ) { |
|
|
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->{__handlers}->{'file'}->{ $ext }->($self); |
|
86
|
|
|
|
|
|
|
} elsif ( defined( $self->{__handlers}->{file}->{'*'} ) ) { |
|
87
|
0
|
|
|
|
|
|
$self->{__handlers}->{'file'}->{'*'}->($self); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} elsif (-d $path_file) { |
|
90
|
0
|
0
|
|
|
|
|
$self->{__handlers}->{'index'}->{'*'}->($self) |
|
91
|
|
|
|
|
|
|
if ( defined( $self->{__handlers}->{'index'}->{'*'} ) ); |
|
92
|
0
|
|
|
|
|
|
$self->{__index_depth}++; |
|
93
|
0
|
0
|
0
|
|
|
|
_process_dir($self, $path_file) |
|
94
|
|
|
|
|
|
|
if (! $self->depth || $self->{__index_depth} < $self->depth); |
|
95
|
0
|
|
|
|
|
|
$self->{__index_depth}--; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
0
|
|
|
|
|
|
pop(@{ $self->{__stack} }); |
|
|
0
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
1; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# accessors methods to current state while streaming. |
|
104
|
0
|
0
|
|
0
|
1
|
|
sub dir { $_[0]->{__stack}->[-1]->{path} || $path_delim; } |
|
105
|
|
|
|
|
|
|
sub relative_dir { |
|
106
|
0
|
|
0
|
0
|
1
|
|
my $base = $_[1] || $_[0]->base; |
|
107
|
0
|
0
|
|
|
|
|
$_[0]->{__stack}->[-1]->{path}=~m/^$base(.*)/ ? $1 : ''; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
0
|
|
0
|
1
|
|
sub file { $_[0]->{__stack}->[-1]->{file} || ''; } |
|
110
|
0
|
0
|
|
0
|
1
|
|
sub ext { $_[0]->{__stack}->[-1]->{ext} || ''; } |
|
111
|
|
|
|
|
|
|
sub name { |
|
112
|
0
|
|
|
0
|
1
|
|
my $x=$_[0]->{__stack}->[-1]; |
|
113
|
0
|
|
|
|
|
|
File::Spec->catfile( $x->{path}, $x->{file} ); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
sub relative_name { |
|
116
|
0
|
|
0
|
0
|
1
|
|
my $base = $_[1] || $_[0]->base; |
|
117
|
0
|
|
|
|
|
|
$_[0]->name=~/^$base(.*)/; |
|
118
|
0
|
|
|
|
|
|
$1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
0
|
|
|
0
|
1
|
|
sub index_depth { $_[0]->{__index_depth}; } |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# experimental convienence method for reading files automatically based on type. |
|
123
|
|
|
|
|
|
|
# should this die silently or should a default handler be implemented? |
|
124
|
|
|
|
|
|
|
sub read_file { |
|
125
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
126
|
0
|
|
|
|
|
|
my $file = shift; |
|
127
|
0
|
|
|
|
|
|
(my $ext) = $file=~/\.([^.]*)$/; |
|
128
|
0
|
0
|
|
|
|
|
if ( my $hdlr = $self->{__handlers}->{'read'}->{$ext} ) { |
|
|
|
0
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return $hdlr->($self, $file, @_); |
|
130
|
|
|
|
|
|
|
} elsif ( my $hdlr = $self->{__handlers}->{'read'}->{'*'} ) { |
|
131
|
0
|
|
|
|
|
|
return $hdlr->($self, $file, @_); |
|
132
|
|
|
|
|
|
|
} else { |
|
133
|
0
|
|
|
|
|
|
warn "Undefined handler for file extension: $ext"; |
|
134
|
0
|
|
|
|
|
|
return ''; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |