Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selection of an encoding on slurp/spew in Mojo::File #2089

Merged
merged 3 commits into from
Aug 14, 2023

Conversation

genio
Copy link
Contributor

@genio genio commented Jul 29, 2023

Summary

Alter Mojo::File to:

  • Allow slurp and decode with $file->slurp('UTF-8'); etc.
  • Allow spew and encode with $file->spew('contents', 'UTF-8'); etc.

Motivation

As we discussed on IRC, allowing these options not only makes it easier for users as well as bring things more inline with what is allowed in the Mojo.js framework.

t/mojo/file.t Show resolved Hide resolved
t/mojo/file.t Outdated Show resolved Hide resolved
Grinnz
Grinnz previously approved these changes Jul 29, 2023
Copy link
Contributor

@Grinnz Grinnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks quite useful to me. I assume spew is being added because spurt's API can't handle another argument as it would just use it as data.

@genio
Copy link
Contributor Author

genio commented Jul 29, 2023

@Grinnz Correct. Since spurt can take an array of content, we can't easily check the last argument. Discussion was that spurt would likely be done away with in time

t/mojo/file.t Outdated Show resolved Hide resolved
Copy link
Member

@marcusramberg marcusramberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of this change.

Copy link
Member

@jhthorsen jhthorsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad we have both spew and spurt, but I like spew better, so I'm giving this change 👍

}

sub spurt {
my ($self, $content) = (shift, join '', @_);
sub spew {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mergify mergify bot merged commit 978d8c8 into mojolicious:main Aug 14, 2023
10 checks passed
@karenetheridge
Copy link
Contributor

This is great; thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants