Use isa to determine if a given image is a Plots::Plot, WWPlot, or LaTeXImage.#1450
Open
drgrice1 wants to merge 1 commit into
Open
Use isa to determine if a given image is a Plots::Plot, WWPlot, or LaTeXImage.#1450drgrice1 wants to merge 1 commit into
isa to determine if a given image is a Plots::Plot, WWPlot, or LaTeXImage.#1450drgrice1 wants to merge 1 commit into
Conversation
… or `LaTeXImage`.
This simplifies the checks in the `PGbasicmacros.pl` `image` method that
determine if an image is an instance of a `Plots::Plot`, `WWPlot`, or
`LaTeXImage` package and makes it so that any future package that
derives from one of those will work without further modification to the
`image` method. This uses the `isa` method wrapped in an `eval`. So if
something is not blessed, the `isa` call will throw an exception, but
the `eval` catches the exception and ignores it returning false.
This is technically not quite as good as using
`blessed $image_item && $image_item->isa('Package::Name')`, but here
should be fine. The one case that this will now throw an exception for
that the `Scalar::Util::blessed` method would fix is if `$image_item` is
a literal package name that satisfies the `isa` call. For example if
someone were to call `image(WWPlot)` or `image('WWPlot')`. That will now
throw an uncaught exception, since `WWPlot->isa('WWPlot')` will not
throw an exception here and will return true. So the `insertGraph`
method will be called with the package name `WWPlot`, and that code will
throw the exception because it cannot work with the `WWPlot` package
name. That should not be a real problem though, since no one should do
that. Without this pull request that still wouldn't work, but it would
only give the warning "The file name "WWPlot" does not have an
extension. Every file name used as an argument to alias must have an
extension. The permissible extensions are .gif, .jpg, .png, .svg, .pdf,
.mp4, .mpg, .ogg, .webm, .css, .js, .nb, .csv, .tgz, and .html," but the
problem would still render. The same would happen for any package name
that derives from one of `WWPlot`, `Plots::Plot`, or `LaTeXImage`.
Contributor
Member
Author
|
You are talking about the listed allowed extensions in |
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.
This simplifies the checks in the
PGbasicmacros.plimagemethod that determine if an image is an instance of aPlots::Plot,WWPlot, orLaTeXImagepackage and makes it so that any future package that derives from one of those will work without further modification to theimagemethod. This uses theisamethod wrapped in aneval. So if something is not blessed, theisacall will throw an exception, but theevalcatches the exception and ignores it returning false.This is technically not quite as good as using
blessed $image_item && $image_item->isa('Package::Name'), but here should be fine. The one case that this will now throw an exception for that theScalar::Util::blessedmethod would fix is if$image_itemis a literal package name that satisfies theisacall. For example if someone were to callimage(WWPlot)orimage('WWPlot'). That will now throw an uncaught exception, sinceWWPlot->isa('WWPlot')will not throw an exception here and will return true. So theinsertGraphmethod will be called with the package nameWWPlot, and that code will throw the exception because it cannot work with theWWPlotpackage name. That should not be a real problem though, since no one should do that. Without this pull request that still wouldn't work, but it would only give the warning "The file name "WWPlot" does not have an extension. Every file name used as an argument to alias must have an extension. The permissible extensions are .gif, .jpg, .png, .svg, .pdf, .mp4, .mpg, .ogg, .webm, .css, .js, .nb, .csv, .tgz, and .html," but the problem would still render. The same would happen for any package name that derives from one ofWWPlot,Plots::Plot, orLaTeXImage.