Browse Source

import Dir::Watch from my home repo


git-svn-id: svn://127.0.0.1/Perl/Dir::Watch/trunk@118 0c1c3402-1be1-de11-8092-0022686faf
master
Zane C. B-H 9 years ago
commit
73a897f60e

+ 10
- 0
Dir-Watch/.cvsignore View File

@@ -0,0 +1,10 @@
1
+blib*
2
+Makefile
3
+Makefile.old
4
+Build
5
+_build*
6
+pm_to_blib*
7
+*.tar.gz
8
+.lwpcookies
9
+Dir-Watch-*
10
+cover_db

+ 5
- 0
Dir-Watch/Changes View File

@@ -0,0 +1,5 @@
1
+Revision history for Dir-Watch
2
+
3
+0.01    Date/time
4
+        First version, released on an unsuspecting world.
5
+

+ 8
- 0
Dir-Watch/MANIFEST View File

@@ -0,0 +1,8 @@
1
+Changes
2
+MANIFEST
3
+Makefile.PL
4
+README
5
+lib/Dir/Watch.pm
6
+t/00-load.t
7
+t/pod-coverage.t
8
+t/pod.t

+ 20
- 0
Dir-Watch/Makefile.PL View File

@@ -0,0 +1,20 @@
1
+use strict;
2
+use warnings;
3
+use ExtUtils::MakeMaker;
4
+
5
+WriteMakefile(
6
+			  NAME                => 'Dir::Watch',
7
+			  AUTHOR              => 'Zane C. Bowers <vvelox@vvelox.net>',
8
+			  VERSION_FROM        => 'lib/Dir/Watch.pm',
9
+			  ABSTRACT_FROM       => 'lib/Dir/Watch.pm',
10
+			  ($ExtUtils::MakeMaker::VERSION >= 6.3002
11
+			   ? ('LICENSE'=> 'perl')
12
+			   : ()),
13
+			  PL_FILES            => {},
14
+			  PREREQ_PM => {
15
+							'Test::More'=>0,
16
+							'Cwd'=>0,
17
+							},
18
+			  dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
19
+			  clean               => { FILES => 'Dir-Watch-*' },
20
+			  );

+ 52
- 0
Dir-Watch/README View File

@@ -0,0 +1,52 @@
1
+Dir-Watch
2
+
3
+The README is used to introduce the module and provide instructions on
4
+how to install the module, any machine dependencies it may have (for
5
+example C compilers and installed libraries) and any other information
6
+that should be provided before the module is installed.
7
+
8
+A README file is required for CPAN modules since CPAN extracts the README
9
+file from a module distribution so that people browsing the archive
10
+can use it to get an idea of the module's uses. It is usually a good idea
11
+to provide version information here so that people can decide whether
12
+fixes for the module are worth downloading.
13
+
14
+
15
+INSTALLATION
16
+
17
+To install this module, run the following commands:
18
+
19
+	perl Makefile.PL
20
+	make
21
+	make test
22
+	make install
23
+
24
+SUPPORT AND DOCUMENTATION
25
+
26
+After installing, you can find documentation for this module with the
27
+perldoc command.
28
+
29
+    perldoc Dir::Watch
30
+
31
+You can also look for information at:
32
+
33
+    RT, CPAN's request tracker
34
+        http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dir-Watch
35
+
36
+    AnnoCPAN, Annotated CPAN documentation
37
+        http://annocpan.org/dist/Dir-Watch
38
+
39
+    CPAN Ratings
40
+        http://cpanratings.perl.org/d/Dir-Watch
41
+
42
+    Search CPAN
43
+        http://search.cpan.org/dist/Dir-Watch/
44
+
45
+
46
+COPYRIGHT AND LICENCE
47
+
48
+Copyright (C) 2009 Zane C. Bowers
49
+
50
+This program is free software; you can redistribute it and/or modify it
51
+under the same terms as Perl itself.
52
+

+ 186
- 0
Dir-Watch/lib/Dir/Watch.pm View File

@@ -0,0 +1,186 @@
1
+package Dir::Watch;
2
+
3
+use warnings;
4
+use strict;
5
+use Cwd;
6
+
7
+=head1 NAME
8
+
9
+Dir::Watch - Watches the current directory for file additions or removals.
10
+
11
+=head1 VERSION
12
+
13
+Version 0.0.0
14
+
15
+=cut
16
+
17
+our $VERSION = '0.0.0';
18
+
19
+
20
+=head1 SYNOPSIS
21
+
22
+    use Dir::Watch;
23
+
24
+    $dirwatch=Dir::Watch->new;
25
+
26
+    if($dirwatch->check){
27
+        print "There are new items\n";
28
+    }
29
+
30
+=head1 METHODS
31
+
32
+=head2 new
33
+
34
+This initiates the object.
35
+
36
+    $dirwatch=Dir::Watch->new;
37
+
38
+=cut
39
+
40
+sub new{
41
+	my %args;
42
+#	if (defined($_[1])) {
43
+#		%args=%{$_[1]};
44
+#	}
45
+
46
+	$args{dir}=cwd;
47
+
48
+	my $self={ dir=>$args{dir} };
49
+	bless $self;
50
+
51
+	#get the stuff in the current directory
52
+	opendir(NEWREAD, $args{dir});
53
+	my @direntries=readdir(NEWREAD);
54
+	closedir(NEWREAD);
55
+
56
+	#builds the hash that will be used for checking
57
+	my %dirhash;
58
+	my $int=0;
59
+	while(defined($direntries[$int])){
60
+		$dirhash{$direntries[$int]}=1;
61
+
62
+		$int++;
63
+	}
64
+	$self->{dirhash}=\%dirhash;
65
+	
66
+	return $self;
67
+}
68
+
69
+=head2 check
70
+
71
+This checks for a new directories or files.
72
+
73
+If any thing has been added or removed, true is returned.
74
+
75
+If nothing has been added or removed, false is returned.
76
+
77
+    if(!$dirwatch->check){
78
+        print "There have been either files/directories added or removed.\n";
79
+    }
80
+
81
+=cut
82
+
83
+sub check{
84
+	my $self=$_[0];
85
+
86
+	#get the stuff in the current directory
87
+	opendir(CHECKREAD, $self->{dir});
88
+	my @direntries=readdir(CHECKREAD);
89
+	closedir(CHECKREAD);
90
+
91
+	#builds the hash that will be used for checking
92
+	my %dirhash;
93
+	my $int=0;
94
+	while(defined($direntries[$int])){
95
+		$dirhash{$direntries[$int]}=1;
96
+
97
+		$int++;
98
+	}
99
+
100
+	#check for anything new
101
+	$int=0;
102
+	while (defined($direntries[$int])) {
103
+		if (!defined( $self->{dirhash}{ $direntries[$int] } )) {
104
+			$self->{dirhash}=\%dirhash;
105
+			return 1;
106
+		}
107
+
108
+		$int++;
109
+	}
110
+
111
+	#check for any thing removed
112
+	$int=0;
113
+	my @keys=keys(%{ $self->{dirhash} });
114
+	while (defined( $keys[$int] )) {
115
+		if (!defined( $dirhash{ $keys[$int] } )) {
116
+			$self->{dirhash}=\%dirhash;
117
+			return 1;
118
+		}
119
+
120
+		$int++;
121
+	}
122
+
123
+	#saves the dir hash for checking later
124
+	$self->{dirhash}=\%dirhash;
125
+
126
+	#return false as if we got here nothing new was found or old was removed
127
+	return 0;
128
+}
129
+
130
+=head1 AUTHOR
131
+
132
+Zane C. Bowers, C<< <vvelox at vvelox.net> >>
133
+
134
+=head1 BUGS
135
+
136
+Please report any bugs or feature requests to C<bug-dir-watch at rt.cpan.org>, or through
137
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dir-Watch>.  I will be notified, and then you'll
138
+automatically be notified of progress on your bug as I make changes.
139
+
140
+
141
+
142
+
143
+=head1 SUPPORT
144
+
145
+You can find documentation for this module with the perldoc command.
146
+
147
+    perldoc Dir::Watch
148
+
149
+
150
+You can also look for information at:
151
+
152
+=over 4
153
+
154
+=item * RT: CPAN's request tracker
155
+
156
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dir-Watch>
157
+
158
+=item * AnnoCPAN: Annotated CPAN documentation
159
+
160
+L<http://annocpan.org/dist/Dir-Watch>
161
+
162
+=item * CPAN Ratings
163
+
164
+L<http://cpanratings.perl.org/d/Dir-Watch>
165
+
166
+=item * Search CPAN
167
+
168
+L<http://search.cpan.org/dist/Dir-Watch/>
169
+
170
+=back
171
+
172
+
173
+=head1 ACKNOWLEDGEMENTS
174
+
175
+
176
+=head1 COPYRIGHT & LICENSE
177
+
178
+Copyright 2009 Zane C. Bowers, all rights reserved.
179
+
180
+This program is free software; you can redistribute it and/or modify it
181
+under the same terms as Perl itself.
182
+
183
+
184
+=cut
185
+
186
+1; # End of Dir::Watch

+ 9
- 0
Dir-Watch/t/00-load.t View File

@@ -0,0 +1,9 @@
1
+#!perl -T
2
+
3
+use Test::More tests => 1;
4
+
5
+BEGIN {
6
+	use_ok( 'Dir::Watch' );
7
+}
8
+
9
+diag( "Testing Dir::Watch $Dir::Watch::VERSION, Perl $], $^X" );

+ 55
- 0
Dir-Watch/t/boilerplate.t View File

@@ -0,0 +1,55 @@
1
+#!perl -T
2
+
3
+use strict;
4
+use warnings;
5
+use Test::More tests => 3;
6
+
7
+sub not_in_file_ok {
8
+    my ($filename, %regex) = @_;
9
+    open( my $fh, '<', $filename )
10
+        or die "couldn't open $filename for reading: $!";
11
+
12
+    my %violated;
13
+
14
+    while (my $line = <$fh>) {
15
+        while (my ($desc, $regex) = each %regex) {
16
+            if ($line =~ $regex) {
17
+                push @{$violated{$desc}||=[]}, $.;
18
+            }
19
+        }
20
+    }
21
+
22
+    if (%violated) {
23
+        fail("$filename contains boilerplate text");
24
+        diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
25
+    } else {
26
+        pass("$filename contains no boilerplate text");
27
+    }
28
+}
29
+
30
+sub module_boilerplate_ok {
31
+    my ($module) = @_;
32
+    not_in_file_ok($module =>
33
+        'the great new $MODULENAME'   => qr/ - The great new /,
34
+        'boilerplate description'     => qr/Quick summary of what the module/,
35
+        'stub function definition'    => qr/function[12]/,
36
+    );
37
+}
38
+
39
+TODO: {
40
+  local $TODO = "Need to replace the boilerplate text";
41
+
42
+  not_in_file_ok(README =>
43
+    "The README is used..."       => qr/The README is used/,
44
+    "'version information here'"  => qr/to provide version information/,
45
+  );
46
+
47
+  not_in_file_ok(Changes =>
48
+    "placeholder date/time"       => qr(Date/time)
49
+  );
50
+
51
+  module_boilerplate_ok('lib/Dir/Watch.pm');
52
+
53
+
54
+}
55
+

+ 18
- 0
Dir-Watch/t/pod-coverage.t View File

@@ -0,0 +1,18 @@
1
+use strict;
2
+use warnings;
3
+use Test::More;
4
+
5
+# Ensure a recent version of Test::Pod::Coverage
6
+my $min_tpc = 1.08;
7
+eval "use Test::Pod::Coverage $min_tpc";
8
+plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
9
+    if $@;
10
+
11
+# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
12
+# but older versions don't recognize some common documentation styles
13
+my $min_pc = 0.18;
14
+eval "use Pod::Coverage $min_pc";
15
+plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
16
+    if $@;
17
+
18
+all_pod_coverage_ok();

+ 12
- 0
Dir-Watch/t/pod.t View File

@@ -0,0 +1,12 @@
1
+#!perl -T
2
+
3
+use strict;
4
+use warnings;
5
+use Test::More;
6
+
7
+# Ensure a recent version of Test::Pod
8
+my $min_tp = 1.22;
9
+eval "use Test::Pod $min_tp";
10
+plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
11
+
12
+all_pod_files_ok();

Loading…
Cancel
Save