Perl CGI. Can I be sure of the order of <style> tags I use?
If I create two style strings, like so
my $style =<<'EOF';
<-- @import url("foo.css"); -->
EOF
my $style2 =<<'EOF';
<-- #thing_in_foo.css_that_I_want_to_override a {attributes;} -->
EOF
And I wish to include them in start_html like so:
print $q->start开发者_JAVA技巧_html({
-style => [
{-code=>$style},
{-code=>$style2}
]);
Or some such.
The long-term goal is to subclass the CGI module with a mess of defaults. I want to let the user pass some additional hash references to the object, like so:my $q = subCGI->new({-code=>$style2});
The object will within build the start_html parameters, and I'd like to put that hash reference into the -style array. I plan to have some already in there; the intent is to have the user pass any css in the new() parameter such that it will cascade over the defaults.
I hope that makes sense.
Any subsequent additions to a hash using the same key as used previously will always overwrite the first. That is,
my %hash = (
key => "value 1",
key => "value 2",
);
...will always yield a key with value "value 2", never "value 1".
It is a somewhat common technique to use this to allow optional overrides, e.g.:
sub wrapper_around_something_common
{
# get optional options from the caller
my %options = @_;
some_other_function(
key_1 => 'some default',
key_2 => 'another default',
%options, # and override with any options provided by user
)
}
精彩评论