Anonymous avatar Anonymous committed 915aa19

Added the File::Find::Object::TreeCreate module under t/lib for aiding
in testing the module. Currently contains the get_path method that
facilitates creating platform independant paths.

Comments (0)

Files changed (3)

 Changes
+lib/File/Find/Object/internal.pm
 lib/File/Find/Object.pm
-lib/File/Find/Object/internal.pm
 Makefile.PL
 MANIFEST			This list of files
 META.yml
 README
 t/01ffo.t
+t/02tree-create.t
+t/lib/File/Find/Object/TreeCreate.pm
 tree

t/02tree-create.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+BEGIN
+{
+    use File::Spec;
+    use lib File::Spec->catdir(File::Spec->curdir(), "t", "lib");
+}
+
+use File::Find::Object::TreeCreate;
+
+{
+    my $t = File::Find::Object::TreeCreate->new();
+
+    # TEST
+    ok ($t, "TreeCreate object was initialized");
+
+    # TEST
+    is ($t->get_path("./t/file.txt"), File::Spec->catfile(File::Spec->curdir(), "t", "file.txt"));
+
+    # TEST
+    is ($t->get_path("./t/mydir/"), File::Spec->catdir(File::Spec->curdir(), "t", "mydir"));
+
+    # TEST
+    is ($t->get_path("./t/hello/there/world.jpg"), File::Spec->catfile(File::Spec->curdir(), "t", "hello", "there", "world.jpg"));
+
+    # TEST
+    is ($t->get_path("./one/two/three/four/"), File::Spec->catdir(File::Spec->curdir(), "one", "two", "three", "four"));
+}

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

+package File::Find::Object::TreeCreate;
+
+use strict;
+use warnings;
+
+use File::Spec;
+
+sub new
+{
+    my $class = shift;
+    my $self = {};
+    bless $self, $class;
+    $self->_initialize(@_);
+    return $self;
+}
+
+sub _initialize
+{
+}
+
+sub get_path
+{
+    my $self = shift;
+    my $path = shift;
+
+    my @components;
+
+    if ($path =~ s{^./}{})
+    {
+        push @components, File::Spec->curdir();
+    }
+    
+    my $is_dir = ($path =~ s{/$}{});
+    push @components, split(/\//, $path);
+    if ($is_dir)
+    {
+        return File::Spec->catdir(@components);
+    }
+    else
+    {
+        return File::Spec->catfile(@components);
+    }
+}
+
+1;
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.