Open
Conversation
Move `sprintf` message formatting into its own object method of
`HP::Server` and make `add_info()`, `add_extendedinfo()` and
`add_message()` use it. This way
* The first argument is always a format string. Should there be no
further arguments, the `sprintf` is a no-op.
* Additional arguments can be either scalar references or plain scalars.
Every reference is taken to be the name of an attribute to retrieve;
plain scalars are taken as-is.
This saves a lot of typing and makes code somewhat easier to read by
replacing all the nested `sprintf "foo %s bar", $self->{attr} ...` calls
with `'foo %s bar', \'attr'`.
Considering that attribute lookups are much more frequent in arguments to
`add_info` etc. than calculated arguments, it would make sense to
reverse the semantics and insert scalar references as-is while plain
scalars would be taken as attribute names. This would save a heap of
unsightly backslashes. However, the way it is now is completely
compatible with the old calling conventions so it should be the gentler
change after all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move
sprintfmessage formatting into its own object method ofHP::Serverand makeadd_info(),add_extendedinfo()andadd_message()use it. This waysprintfis a no-op.This saves a lot of typing and makes code somewhat easier to read by replacing all the nested
add_info(sprintf "foo %s bar %d%s", $self->{attr1}, $self->{attr2}, 'quux')calls with
add_info('foo %s bar %d%s', \'attr1', \'attr2', 'quux').Considering that attribute lookups are much more frequent in arguments to
add_infoetc. than calculated arguments, it would make sense to reverse the semantics and insert scalar references as-is while plainscalars would be taken as attribute names. This would save a heap of unsightly backslashes. However, the way it is now is completely compatible with the old calling conventions so it should be the gentler change after all.
I just came up with this while adding
--customfanspeedsand actually did it first, however to make the two changes independent I based the customfanspeeds change on the master as well as this is a fairly big one stylistically :)