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

Refactor signature parsing into its own class #96

Merged
merged 16 commits into from Mar 24, 2014

Conversation

schwern
Copy link
Contributor

@schwern schwern commented Mar 6, 2014

This moves all the code for tokenizing, parsing and checking signatures and parameters into its own class, the awkwardly named Method::Signatures::Signature. This makes the code make more sense and it is potentially easier to test and work with separate from the Devel::Declare madness.

Right now this is an internal refactoring. The eventual external goal is to provide a way for users to parsed and examine signatures separate from the whole Devel::Declare thing like Parse::Method::Signatures does. The immediate use is to replace PMS in TryCatch to de-Moosify and speed up TryCatch's load time.

It would also make sense to move the code generation functionality into MS::Signature and MS::Parameter, leaving MS to deal just with the Devel::Declare magic, but that can happen later.

As this touches a lot of code, it would be good to see this merged sooner rather than later. I did my best to break it up into reviewable chunks.

If it uses ->{overall}{num_named} it breaks the yadayada handling.  Must be a leftover
from before yadayada.
MS::Signature is just a basic data container object for now to
prepare for moving the functionality out of MS and into MS::Signature.
This turns out to be important for neg_and_odd_prime() in t/where.t
and in general our order of evaluation should be predictable.
…uses.

Checking 'if $sig->where' will always return true, so the clause
was a waste of time anyway.

$sig->where is always initialized, no reason to spend the extra time
checking if there's anything in it, the for loop will do that for us.
Save a method call.
Makes life easier down the line, especially when it's being
passed into the MS::Signature object which has a Str type.
Eventually we'll want the Signature to handle the default invocant
logic, but for refactoring it's just getting in the way.
Its really "reduce the signature string down to just the parameter list".

I'm kinda waffling between "do everything in one build step" and
"only calculate on demand".
No need to split them anymore.

parse_signature() seemed more namey of the two.
No need for the special check that the prototype has already been
split, we're only calling it once and it's going away soon.
MS::Signature will need it shortly.

MS::Parser is rapidly becoming a utility class.
All the logic for parsing the signature is now in MS::Siganture.

MS::Signature and MS::Parameter can now check themselves via
->check methods.

Tokenizing via split_proto() remains in MS::Parser for the moment
just to keep this refactoring small.
parse_signature() is a better name, but all that functionality will
move into MS::Signature so it's moot.
MS::Parser is now just a utility library and needs to be renamed.

MS::Signature now completely handles signature parsing.

I'm pretty sure MS::Signature could hand MS::Parameter pieces of
the PPI document and avoid having to reparse each parameter.
Parsing is done in MS::Signature and MS::Parameter now.
Leftover from a58cebe before
the stack handling was moved to carp_location_for().
@schwern
Copy link
Contributor Author

schwern commented Mar 6, 2014

The Travis failure is due to experimental being broken on 5.8. Merge #97 and resubmit to Travis.

Conflicts:
	lib/Method/Signatures.pm
@barefootcoder
Copy link
Contributor

Code looks good to me. I merged in the code from #97 and Travis now passes. I'll merge this in as well.

barefootcoder added a commit that referenced this pull request Mar 24, 2014
Refactor signature parsing into its own class
@barefootcoder barefootcoder merged commit 2666fd3 into master Mar 24, 2014
@barefootcoder barefootcoder deleted the refactor/signature_class branch March 24, 2014 00:15
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.

None yet

2 participants