forked from graphviz-perl/GraphViz2
/
Filer.pm
214 lines (130 loc) · 4.24 KB
/
Filer.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package GraphViz2::Filer;
use strict;
use warnings;
use warnings qw(FATAL utf8); # Fatalize encoding glitches.
use File::Basename; # For basename().
use File::Slurp; # For read_file().
use Moo;
our $VERSION = '2.46';
# ------------------------------------------------
sub get_annotations
{
my($self) = @_;
my($dir_name) = 'scripts';
$|=1;
opendir(my $fh, $dir_name);
my(@file_name) = sort grep{! -d $_} readdir $fh;
closedir $fh;
my(%annotation);
my(@line);
my($s);
for my $file_name (@file_name)
{
@line = read_file(File::Spec -> catfile($dir_name, $file_name), {chomp => 1});
if ( ($#line >= 3) && ($line[3] =~ /^# Annotation: (.+)$/) )
{
# Preserve $1 in case basename changes it.
$s = $1;
$annotation{basename($file_name, '.pl')} = $s;
}
}
return %annotation;
} # End of get_annotations.
# ------------------------------------------------
sub get_files
{
my($self, $dir_name, $type) = @_;
opendir(my $fh, $dir_name);
my(@file) = sort grep{/$type$/} readdir $fh;
closedir $fh;
my(%file);
for my $file_name (@file)
{
$file{basename($file_name, ".$type")} = $file_name;
}
return %file;
} # End of get_files.
# ------------------------------------------------
sub get_scripts
{
my($self) = @_;
my($dir_name) = 'scripts';
opendir(my $fh, $dir_name);
my(@file_name) = sort grep{! -d $_ && /\.pl$/} readdir $fh;
closedir $fh;
my(@line);
my(%script);
for my $file_name (map{File::Spec -> catfile($dir_name, $_)} @file_name)
{
@line = read_file($file_name, {chomp => 1});
if ( ($#line >= 3) && ($line[3] =~ /^# Annotation: (?:.+)$/) )
{
$script{basename($file_name, '.pl')} = $file_name;
}
}
return %script;
} # End of get_scripts.
# -----------------------------------------------
1;
=pod
=head1 NAME
L<GraphViz2::Filer> - Some utils to simplify testing and generating the demo page
=head1 Synopsis
See L<GraphViz2/Synopsis>.
See t/tokens.t.
=head1 Description
Some utils to simplify testing.
End-users do not need to call the methods in this module.
=head1 Distributions
This module is available as a Unix-style distro (*.tgz).
See L<http://savage.net.au/Perl-modules/html/installing-a-module.html>
for help on unpacking and installing distros.
=head1 Installation
Install L<GraphViz2> as you would for any C<Perl> module:
Run:
cpanm GraphViz2
or run:
sudo cpan GraphViz2
or unpack the distro, and then either:
perl Build.PL
./Build
./Build test
sudo ./Build install
or:
perl Makefile.PL
make (or dmake or nmake)
make test
make install
=head1 Constructor and Initialization
=head2 Calling new()
C<new()> is called as C<< my($obj) = GraphViz2::Filer -> new(k1 => v1, k2 => v2, ...) >>.
It returns a new object of type C<GraphViz2::Filer>.
=head1 Methods
=head2 get_annotations()
Returns a hash (sic) keyed by *.pl name, with the values being the text off line 3 of each script.
This text is used to annotate html/index.html, the output of scripts/generate.demo.pl.
=head2 get_files($dir_name, $type)
Returns a list of files from the given $dir_name, whose type (extension) matches $type.
See t/tokens.t.
=head2 get_scripts()
Returns a hash (sic) keyed by *.pl name, with the values being the full path to the script.
=head1 Thanks
Many thanks are due to the people who chose to make L<Graphviz|http://www.graphviz.org/> Open Source.
And thanks to L<Leon Brocard|http://search.cpan.org/~lbrocard/>, who wrote L<GraphViz>, and kindly gave me co-maint of the module.
=head1 Version Numbers
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
=head1 Machine-Readable Change Log
The file Changes was converted into Changelog.ini by L<Module::Metadata::Changes>.
=head1 Support
Email the author, or log a bug on RT:
L<https://rt.cpan.org/Public/Dist/Display.html?Name=GraphViz2>.
=head1 Author
L<GraphViz2> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2011.
Home page: L<http://savage.net.au/index.html>.
=head1 Copyright
Australian copyright (c) 2011, Ron Savage.
All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Perl License, a copy of which is available at:
http://dev.perl.org/licenses/
=cut