[RFC] Mojo::File

130 views
Skip to first unread message

sri

unread,
Jan 2, 2017, 2:35:00 PM1/2/17
to Mojolicious
There's a lot of File::* modules we use in Mojolicious (File::Basename, File::Spec, File::Find,
File::Copy, File::Path...). Their use is pretty decentralized at the moment, even though we've
already written our own little extensions like Mojo::Util::files/slurp/spurt.

So, i've been thinking that maybe it would make sense to encapsulate all that stuff a bit in a
new object, which i've called Mojo::File in the (still unfinished) proof-of-concept branch.


Since i'm still on the fence about this proposal, the final decision will depend entirely on
feedback from the community (that's you!). Let me know what you think.

--
sebastian

sri

unread,
Jan 2, 2017, 2:41:47 PM1/2/17
to Mojolicious
I know, there's no documentation, so it might be a bit hard to judge. The tests should
give you an idea of what functionality to expect though.


The ultimate goal is to turn file system interactions into fun little one-liners, like this one,
which lists files recursively.

    path('/etc')->list_tree->grep('is_file')->join("\n")->say

--
sebastian

Tobias Oetiker

unread,
Jan 2, 2017, 2:45:21 PM1/2/17
to mojol...@googlegroups.com

> On 2 Jan 2017, at 20:35, sri <kra...@gmail.com> wrote:
> [...]
> So, i've been thinking that maybe it would make sense to encapsulate all that stuff a bit in a new object, which i've called Mojo::File in the (still unfinished) proof-of-concept branch.
>
> https://github.com/kraih/mojo/compare/mojo_file
>
> Since i'm still on the fence about this proposal, the final decision will depend entirely on feedback from the community (that's you!). Let me know what you think.

I like the idea, as it will allow for optimizations further down the line by replacing existing implementations with our own, without affecting the code that is using the Mojo::File functions ...

cheers
Tobi

Stefan Adams

unread,
Jan 2, 2017, 2:46:00 PM1/2/17
to mojolicious

On Mon, Jan 2, 2017 at 1:35 PM, sri <kra...@gmail.com> wrote:
encapsulate all that stuff a bit in a new object

I like this.  It gives me a single spot to understand file-based operations and it allows me to see a uniform interface.

Stefan Adams

unread,
Jan 2, 2017, 2:49:58 PM1/2/17
to mojolicious
Why not a Mojo::File interface for:

L38 | has tmpdir => sub { $ENV{MOJO_TMPDIR} || File::Spec->tmpdir };

sri

unread,
Jan 2, 2017, 2:50:32 PM1/2/17
to Mojolicious
I like the idea, as it will allow for optimizations further down the line by replacing existing implementations with our own, without affecting the code that is using the Mojo::File functions ...

Funny you bring up optimizations. One of my main concerns has been the object-oriented
API, and especially the cost of instantiating so many objects. There are a few hot-spots, like
the Morbo file checker, where the difference could be significant.


I'd really appreciate some testing there, since my time is a bit limited at the moment.

--
sebastian

sri

unread,
Jan 2, 2017, 2:53:20 PM1/2/17
to Mojolicious
L38 | has tmpdir => sub { $ENV{MOJO_TMPDIR} || File::Spec->tmpdir };

Mojo::Asset::File has some very special and kinda unique needs (more than this line)... and
i'm very unsure about how much of it to push into Mojo::File.

--
sebastian

M. Aaron Bossert

unread,
Jan 3, 2017, 7:45:13 AM1/3/17
to Mojolicious
Well, "Tommy likey!" ...it has my vote...





--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

sri

unread,
Jan 7, 2017, 1:41:47 PM1/7/17
to Mojolicious
I know, there's no documentation, so it might be a bit hard to judge.

There is now also some documentation.


Even though i'm still not sure if it should be added to Mojolicious.

--
sebastian 

Stefan Adams

unread,
Jan 7, 2017, 2:29:32 PM1/7/17
to mojolicious

On Sat, Jan 7, 2017 at 12:41 PM, sri <kra...@gmail.com> wrote:
Even though i'm still not sure if it should be added to Mojolicious.

Well I think it's fantastic and I know I'll use it all the time!

I certainly cannot speak to the impact it will have on Mojo core.

sri

unread,
Jan 7, 2017, 5:40:53 PM1/7/17
to Mojolicious
Putting it up for a vote, everybody is welcome to participate.


--
sebastian

sri

unread,
Jan 9, 2017, 1:02:16 PM1/9/17
to Mojolicious
Putting it up for a vote, everybody is welcome to participate.

And it passed the vote! \o/

--
sebastian 

Stefan Adams

unread,
Jan 9, 2017, 1:32:35 PM1/9/17
to mojolicious

On Mon, Jan 9, 2017 at 12:02 PM, sri <kra...@gmail.com> wrote:
And it passed the vote! \o/

That was the highest vote count I've seen!  Smashing success!!  It was really great to see a lot of people weighing in.  Such user participation is really great for the project and for the community!

sri

unread,
Jan 10, 2017, 9:41:11 AM1/10/17
to Mojolicious
Smashing success!!  It was really great to see a lot of people weighing in.  Such user participation is really great for the project and for the community!

Yes, indeed! And Mojo::File has now been released to CPAN with Mojolicious 7.15.

--
sebastian

Andrey Khozov

unread,
Jan 10, 2017, 12:03:58 PM1/10/17
to Mojolicious
Are there any plans for adding Mojo::File::remove_tree method, opposite to make_path?

-- 
Andrey Khozov

sri

unread,
Jan 10, 2017, 12:47:40 PM1/10/17
to Mojolicious
Are there any plans for adding Mojo::File::remove_tree method, opposite to make_path?

Right now the only plan is to support the things we need in core Mojolicious. Everything else will depend on sensible proposals and votes.

--
sebastian 
Reply all
Reply to author
Forward
0 new messages