extract path from full_path if missing
[MojoFacets.git] / lib / MojoFacets / Import / File.pm
index dac817b..926937f 100644 (file)
@@ -13,17 +13,23 @@ use JSON;
 __PACKAGE__->attr('path');
 __PACKAGE__->attr('full_path');
 
+sub ext { '\.(js(on)?|txt)$' }
+
 sub data {
        my $self = shift;
 
        my $path = $self->path;
+       if ( ! $path ) {
+               $path = $self->full_path || die "no path or full_path";
+               $path =~ s{^.+/([^/]+)$}{$1};
+       }
 
        # we could use Mojo::JSON here, but it's too slow
 #      $data = from_json read_file $path;
        my $data = read_file $self->full_path;
        warn "# data snippet: ", substr($data,0,200);
        my @header;
-       if ( $path =~ m/\.js/ ) {
+       if ( $path =~ m/\.js(on)?/ ) {
                Encode::_utf8_on($data);
                $data = from_json $data;
        } elsif ( $path =~ m/\.txt/ ) {