File Coverage

blib/lib/App/FTNDB/Nodelist.pm
Criterion Covered Total %
statement 15 61 24.5
branch 0 10 0.0
condition n/a
subroutine 5 9 55.5
pod 4 4 100.0
total 24 84 28.5


line stmt bran cond sub pod time code
1             package App::FTNDB::Nodelist;
2              
3 2     2   4243 use warnings;
  2         4  
  2         64  
4 2     2   6 use strict;
  2         3  
  2         35  
5 2     2   6 use Carp qw( croak );
  2         2  
  2         617  
6              
7             =head1 NAME
8              
9             App::FTNDB::Nodelist - Fidonet/FTN Nodelist SQL Database operations.
10              
11             =head1 VERSION
12              
13             Version 0.39
14              
15             =cut
16              
17             our $VERSION = '0.39';
18              
19             =head1 DESCRIPTION
20              
21             App::FTNDB::Nodelist is a Perl module containing common nodelist related subroutines
22             for Fidonet/FTN Nodelist related processing on a Nodelist table in an SQL Database. The
23             SQL database engine is one for which a DBD module exists, defaulting to SQLite.
24              
25             =head1 EXPORT
26              
27             The following functions are available in this module: create_nodelist_table(),
28             drop_nodelist_table(), create_ftnnode_index(), remove_ftn_domain(),
29             nodelist_file_info().
30              
31             =head1 FUNCTIONS
32              
33             =head2 create_nodelist_table
34              
35             Syntax: create_nodelist_table($db_handle, $table_name, $db_type);
36              
37             Create an FTN Nodelist table in an SQL database being used for Fidonet/FTN
38             processing, where $db_handle is an existing open database handle, $table_name
39             is the name of the table to be created, and $db_type is the type of database.
40              
41             =cut
42              
43             sub create_nodelist_table {
44              
45 0     0 1   my($db_handle, $table_name, $db_type) = @_;
46              
47 0           my $sql_statement = "CREATE TABLE $table_name( ";
48             # If DB type is PostgreSQL, use SERIAL; else use INTEGER & AUTOINCREMENT
49 0 0         if ($db_type eq 'Pg') {
50 0           $sql_statement .= "id SERIAL PRIMARY KEY NOT NULL, ";
51             } else {
52 0           $sql_statement .= "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ";
53             }
54 0           $sql_statement .= "type VARCHAR(6) DEFAULT '' NOT NULL, ";
55 0           $sql_statement .= "zone SMALLINT DEFAULT '1' NOT NULL, ";
56 0           $sql_statement .= "net SMALLINT DEFAULT '1' NOT NULL, ";
57 0           $sql_statement .= "node SMALLINT DEFAULT '1' NOT NULL, ";
58 0           $sql_statement .= "point SMALLINT DEFAULT '0' NOT NULL, ";
59 0           $sql_statement .= "region SMALLINT DEFAULT '0' NOT NULL, ";
60 0           $sql_statement .= "name VARCHAR(48) DEFAULT '' NOT NULL, ";
61 0           $sql_statement .= "location VARCHAR(48) DEFAULT '' NOT NULL, ";
62 0           $sql_statement .= "sysop VARCHAR(48) DEFAULT '' NOT NULL, ";
63 0           $sql_statement .= "phone VARCHAR(32) DEFAULT '000-000-000-000' NOT NULL, ";
64 0           $sql_statement .= "baud CHAR(6) DEFAULT '300' NOT NULL, ";
65 0           $sql_statement .= "flags VARCHAR(128) DEFAULT ' ' NOT NULL, ";
66 0           $sql_statement .= "domain VARCHAR(8) DEFAULT 'fidonet' NOT NULL, ";
67 0           $sql_statement .= "ftnyear SMALLINT DEFAULT '0' NOT NULL, ";
68 0           $sql_statement .= "yearday SMALLINT DEFAULT '0' NOT NULL, ";
69 0           $sql_statement .= "source VARCHAR(16) DEFAULT 'local' NOT NULL, ";
70 0           $sql_statement .= "updated TIMESTAMP DEFAULT 'now' NOT NULL ";
71 0           $sql_statement .= ") ";
72              
73 0 0         $db_handle->do("$sql_statement ") or croak($DBI::errstr);
74              
75 0           return(0);
76              
77             }
78              
79             =head2 create_ftnnode_index
80              
81             Syntax: create_ftnnode_index($db_handle, $table_name);
82              
83             Create an index named ftnnode on an FTN Nodelist table in an SQL database being
84             used for Fidonet/FTN processing, where $db_handle is an existing open database
85             handle and $table_name is the name of the table that is being indexed. The
86             index is created on the following fields: zone, net, node, point, and domain.
87              
88             =cut
89              
90             sub create_ftnnode_index {
91              
92 0     0 1   my($db_handle, $table_name) = @_;
93              
94 0           my $sql_statement = "CREATE INDEX ftnnode ";
95 0           $sql_statement .= "ON $table_name (zone,net,node,point,domain,ftnyear,yearday) ";
96              
97 0 0         $db_handle->do("$sql_statement") or croak($DBI::errstr);
98              
99 0           return(0);
100              
101             }
102              
103             =head2 remove_ftn_domain
104              
105             Syntax: remove_ftn_domain($db_handle, $table_name, $domain);
106              
107             Remove all entries for a particular FTN domain from an FTN nodelist table in an SQL
108             database being used for FTN processing; where $db_handle is an existing open database
109             handle and $table_name is the name of the table from which the FTN domain $domain is
110             being removed.
111              
112             =cut
113              
114             sub remove_ftn_domain {
115              
116 0     0 1   my($db_handle, $table_name, $domain) = @_;
117              
118 0           my $sql_statement = "DELETE FROM $table_name WHERE domain = '$domain'";
119              
120 0 0         $db_handle->do("$sql_statement") or croak($DBI::errstr);
121              
122 0           return(0);
123              
124             }
125              
126             =head2 nodelist_file_info
127              
128             Syntax: %nodelist_info = nodelist_file_info($nodelist_file);
129              
130             Returns a hash containing the header and other information for a nodelist file
131             when given the file name and path for an FTN nodelist file. The possible keys
132             returned in the hash are as follows:
133              
134             =over 4
135              
136             =item Year
137              
138             The four digit year from the nodelist file header line. Defaults to the year
139             number from the nodelist file time stamp.
140              
141             =item YearDay
142              
143             The year day number from the nodelist file header line. Defaults to the file
144             suffix of the nodelist, which is assumed to be a three digit number.
145              
146             =item FileYear
147              
148             The four digit year number from the timestamp of the nodelist file.
149              
150             =item FileYDay
151              
152             The year day number from the timestamp of the nodelist file.
153              
154             =item HeaderLine
155              
156             The header line (first line) from the nodelist file as a string.
157              
158             =back
159              
160             =cut
161              
162             sub nodelist_file_info {
163              
164 0     0 1   my $nodelist_file = shift;
165              
166 0           my (%info, $nl);
167              
168 2     2   9 use File::Basename;
  2         2  
  2         181  
169 0           ( $info{'FileName'}, $info{'FileDir'}, $info{'FileSuffix'} ) = fileparse($nodelist_file, qr/[^.]*/);
170              
171 2     2   870 use File::stat;
  2         9005  
  2         7  
172 0           my $fs = stat($nodelist_file);
173              
174             # year of the converted timestamp is the fifth item
175 0           $info{'FileYear'} = (localtime($fs->mtime))[5] + 1900;
176             # yday of converted timestamp is the seventh item
177 0           $info{'FileYDay'} = (localtime($fs->mtime))[7] + 1;
178              
179             # Read in the first line of the nodelist file.
180 0 0         open $nl, q{<}, $nodelist_file or croak "Cannot open $nodelist_file";
181 0           $info{'HeaderLine'} = <$nl>;
182 0           close $nl;
183              
184             # Year key defaults to the four digit year from the nodelist file timestamp.
185 0           $info{'Year'} = $info{'FileYear'};
186              
187             # YearDay key defaults to the nodelist file suffix.
188 0           $info{'YearDay'} = $info{'FileSuffix'};
189              
190 0           return %info;
191             }
192              
193             =head1 EXAMPLES
194              
195             An example of opening an FTN database, then creating a nodelist table,
196             loading data to it, then creating an index on it, and the closing
197             the database:
198              
199             use App::FTNDB::Nodelist;
200              
201             my $db_handle = open_ftn_database(\%db_option);
202             create_nodelist_table($db_handle, $table_name);
203             ... (Load data to nodelist table)
204             create_ftnnode_index($db_handle, $table_name);
205             close_ftn_database($db_handle);
206              
207             =head1 AUTHOR
208              
209             Robert James Clay, C<< >>
210              
211             =head1 BUGS
212              
213             Please report any bugs or feature requests via the web interface at
214             L. I will be notified,
215             and then you'll automatically be notified of progress on your bug
216             as I make changes.
217              
218             Note that you can also report any bugs or feature requests to
219             C, or through the web interface at
220             L;
221             however, the FTN Database application Issue tracker at the
222             SourceForge project is preferred.
223              
224              
225             =head1 SUPPORT
226              
227             You can find documentation for this module with the perldoc command.
228              
229             perldoc App::FTNDB::Nodelist
230              
231              
232             You can also look for information at:
233              
234             =over 4
235              
236             =item * FTN Database application issue tracker
237              
238             L
239              
240             =item * RT: CPAN's request tracker
241              
242             L
243              
244             =item * Search CPAN
245              
246             L
247              
248             =back
249              
250             =head1 SEE ALSO
251              
252             L, L, and L
253              
254             =head1 COPYRIGHT & LICENSE
255              
256             Copyright 2010-2013 Robert James Clay, all rights reserved.
257              
258             This program is free software; you can redistribute it and/or modify it
259             under the same terms as Perl itself.
260              
261              
262             =cut
263              
264             1; # End of App::FTNDB::Nodelist