Commits

shl...@6f433eb9-a002-0410-945b-ee5462c261ee  committed 566c5f7

Added the ls method and changed contains to cat to return the contents of the
file.

  • Participants
  • Parent commits 3915caf

Comments (0)

Files changed (2)

File t/02tree-create.t

 use strict;
 use warnings;
 
-use Test::More tests => 12;
+use Test::More tests => 13;
 
 BEGIN
 {
     use lib File::Spec->catdir(File::Spec->curdir(), "t", "lib");
 }
 
+use File::Path;
+
 use File::Find::Object::TreeCreate;
 
 {
     ok ($t->is_dir ("./t"), "Checking the is_dir method - true");
     
     # TEST
-    ok ($t->contains("./t/sample-data/h.txt", "Hello."),
-        "Checking the contain method");
+    is ($t->cat("./t/sample-data/h.txt"), "Hello.",
+        "Checking the cat method");
+
+    {
+        mkdir ($t->get_path("./t/sample-data/ls-test"));
+        mkdir ($t->get_path("./t/sample-data/ls-test/a"));
+        open O, ">", $t->get_path("./t/sample-data/ls-test/b.txt");
+        print O "Yowza";
+        close(O);
+        mkdir ($t->get_path("./t/sample-data/ls-test/c"));
+        open O, ">", $t->get_path("./t/sample-data/ls-test/h.xls");
+        print O "FooBardom!\n";
+        close(O);
+        # TEST
+        is_deeply ($t->ls("./t/sample-data/ls-test"),
+            ["a","b.txt","c","h.xls"],
+            "Testing the ls method",
+            );
+        # Cleanup
+        rmtree ($t->get_path("./t/sample-data/ls-test"));
+    }
 }

File t/lib/File/Find/Object/TreeCreate.pm

     return (-d $self->get_path(@_));
 }
 
-sub contains 
+sub cat
 {
-    my ($self, $path, $expected) = @_;
-    open my $in, "<", $self->get_path($path) or
+    my $self = shift;
+    open my $in, "<", $self->get_path(@_) or
         return 0;
     my $data;
     {
         $data = <$in>;
     }
     close($in);
-    return ($data eq $expected);
+    return $data;
 }
 
+sub ls
+{
+    my $self = shift;
+    opendir my $dir, $self->get_path(@_) or
+        return undef;
+    my @files = 
+        sort { $a cmp $b } 
+        grep { !(($_ eq ".") || ($_ eq "..")) }
+        readdir($dir);
+    closedir($dir);    
+    return \@files;
+}
 1;