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

Can we get ->mo->yaml and ->mo->json? #230

Closed
mscha opened this issue Feb 23, 2013 · 2 comments
Closed

Can we get ->mo->yaml and ->mo->json? #230

mscha opened this issue Feb 23, 2013 · 2 comments

Comments

@mscha
Copy link

mscha commented Feb 23, 2013

Having to type
$foo->mo->dump(format=>'yaml')->say
is way too annoying. And it wastes 16 bytes and a couple of seconds every time you use it.
Can we get
$foo->mo->yaml->say
as a shortcut, just like we have
$foo->mo->perl->say
?
(Same thing for json, and any other formats (xml?) that might be added for dump.)

@schwern schwern mentioned this issue Feb 24, 2013
@schwern
Copy link
Contributor

schwern commented Feb 24, 2013

Though I couldn't give a lick about "wasting" 16 bytes, making it even
easier to dump in JSON and YAML makes sense to me.

I have reservations about XML. JSON and YAML are fairly straight
forward translations, but XML is not. However, we don't even do XML yet
so we can blow up that bridge when we come to it.

I request discussions about XML dumping happen in #231.

Since we're going to have more dumping methods, I'd suggest a
nomenclature change. as_blah seems to be the standard name for
methods. This avoids cluttering the meta namespace with random formats
and makes it a bit clearer what they do and how to find them.

perl -> as_perl
yaml -> as_yaml
json -> as_json

This should be a fairly straight forward patch. The code is in
perl5i::2::Meta::Instance. The individual dumper methods exist as
perl, _dump_as_json and _dump_as_yaml. Fiddle the names and the
tests in t/dump/. Leave an alias from as_perl to perl for
compatibility and we can get rid of it in perl5i::3.

Go to it!

notbenh pushed a commit to notbenh/perl5i that referenced this issue Mar 5, 2013
NOTES/POSSIBLE ISSUES:
  - the test is calling ::2 directly rather then latest.
    I was unsure on the going convention for a version specific change
  - I am not using alias to build the aliases.
    It seemed a bit heavy handed so I am using the old-style delegation.
schwern added a commit that referenced this issue Mar 6, 2013
Adding the as_* methods as requested in #230
@schwern
Copy link
Contributor

schwern commented Mar 6, 2013

Now they just need to be documented in perl5i::Meta::Instance. Don't forget that perl is now a backwards compatibility method and as_perl is the real one.

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

No branches or pull requests

3 participants