Skip to content

Commit

Permalink
no need to check for existence of required parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
barefootcoder committed Apr 12, 2011
1 parent d663b9c commit fa3bbd3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Method/Signatures.pm
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ sub inject_for_type_check
my $class = ref $self || $self;
my ($sig) = @_;

return "${class}->type_check('$sig->{type}', $sig->{passed_in}, '$sig->{name}') if $sig->{exists};";
my $check_exists = $sig->{is_optional} ? "if $sig->{exists}" : '';
return "${class}->type_check('$sig->{type}', $sig->{passed_in}, '$sig->{name}') $check_exists;";
}

sub signature_error {
Expand Down

2 comments on commit fa3bbd3

@schwern
Copy link

@schwern schwern commented on fa3bbd3 Jun 7, 2011

Choose a reason for hiding this comment

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

This confused me, because I figured $sig->{exists} was meta information about the signature like everything else. I figured it was a flag, not a hunk of code to check that it exists, so it looked like you were hard coding true or false into the generated code.

I'm not entirely happy with putting hunks of code into the signature, but I see the value. How about check_exists and we can work out a better place to put the code chunks later?

@barefootcoder
Copy link
Owner Author

Choose a reason for hiding this comment

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

This confused me, because I figured $sig->{exists} was meta information about the signature like everything else. I figured it was a flag, not a hunk of code to check that it exists, so it looked like you were hard coding true or false into the generated code.

Hmmm ... I probably misnamed that. I'm basically just saving the chunk of code that you created in inject_for_sig and passing that to inject_for_type_check.

I'm not entirely happy with putting hunks of code into the signature, but I see the value.

Well, putting it into the signature was just the easiest way to get it from one place to another (and I suppose it makes it available for subclasses, if that were useful), but it's certainly not the only way. We could just make it an additional parameter to inject_for_tyep_check. Whatever turns you on, man. :)

How about check_exists and we can work out a better place to put the code chunks later?

That's fine too.

Please sign in to comment.