You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M. Chiasson" <go...@cpan.org> on 2004/03/25 21:39:36 UTC

[Patch mp2] Test tied %Location in sections

As we discussed, instead of trying to use Tie::IxHash behind the scenes
to order %Location blocks and such, we will recommend users to use Tie::
* for themselves like so:

<Perl>
 tie %Location, "My::Tie";

</Perl>

So, until I get around updating the documentation, I've at least tested
that tied %Hashes in <Perl> sections do behave proprely. Only problem I
can think of is that if you use PerlSections->dump, your hash will be
dumped as a hash, not seeing the tie magic. So next time around, if you
load your dumped <Perl> configuration, you'll experience hash ordering
trouble once again.

Index: t/response/TestDirective/perldo.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/perldo.pm,v
retrieving revision 1.7
diff -u -I$Id -r1.7 perldo.pm
--- t/response/TestDirective/perldo.pm	29 Feb 2004 05:28:43 -0000	1.7
+++ t/response/TestDirective/perldo.pm	24 Mar 2004 00:21:05 -0000
@@ -11,7 +11,7 @@
 sub handler {
     my $r = shift;
 
-    plan $r, tests => 14;
+    plan $r, tests => 15;
 
     ok t_cmp('yes', $TestDirective::perl::worked);
     
@@ -27,6 +27,8 @@
     ok not exists $Location{'/perl_sections'};
     ok exists $Location{'/perl_sections_saved'};
     ok t_cmp('PerlSection', $Location{'/perl_sections_saved'}{'AuthName'});
+
+    ok t_cmp('TIED', $Location{'/tied'}, 'Tied %Location');
 
     ok t_cmp('yes', $TestDirective::perl::comments);
 
Index: t/conf/extra.last.conf.in
===================================================================
RCS file: /home/cvs/modperl-2.0/t/conf/extra.last.conf.in,v
retrieving revision 1.16
diff -u -I$Id -r1.16 extra.last.conf.in
--- t/conf/extra.last.conf.in	16 Feb 2004 19:50:12 -0000	1.16
+++ t/conf/extra.last.conf.in	24 Mar 2004 00:21:05 -0000
@@ -12,7 +12,24 @@
 	};
 </Perl>
 
+<Perl>
+ package Tie::PerlSection;
+ use Tie::Hash;
+ @ISA = (Tie::StdHash);
+ sub FETCH { 
+	my ($hash, $key) = @_;
+	if ($key eq '/tied') {
+		return 'TIED';
+	}
+	return $hash->{$key};
+ }
+</Perl>
+
 <Perl >
+#Test tied %Location
+tie %Location, 'Tie::PerlSection';
+$Location{'/tied'} = 'test_tied';
+
 $Apache::Server::SaveConfig = 1;
 $Location{'/perl_sections_saved'} = {
 	'AuthName' => 'PerlSection',
-- 
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: [Patch mp2] Test tied %Location in sections

Posted by David Wheeler <da...@kineticode.com>.
On Mar 25, 2004, at 12:39 PM, Philippe M. Chiasson wrote:

> As we discussed, instead of trying to use Tie::IxHash behind the scenes
> to order %Location blocks and such, we will recommend users to use 
> Tie::
> * for themselves like so:

That's fine, but I think you should also point out that using 
$PerlConfig or @PerlConfig can also help get 'round the problem.

Regards,

David


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Patch mp2] Test tied %Location in sections

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Thu, 2004-03-25 at 13:30 -0800, Stas Bekman wrote: 
> Philippe M. Chiasson wrote:
> 
> >>>Only problem I
> >>>can think of is that if you use PerlSections->dump, your hash will be
> >>>dumped as a hash, not seeing the tie magic. So next time around, if you
> >>>load your dumped <Perl> configuration, you'll experience hash ordering
> >>>trouble once again.
> >>
> >>why can't we keep the tiedness?
> > 
> > 
> > Well, how are you supposed to correctly dump a tie'd object so it can be
> > restored by an eval ?
> 
> simply. if it's tied(), you know which class it was tied into. so when you 
> dump it, add the tie directive to tie it back to the class it was tied to in 
> first place. Or just use Storable?
It's actually a lot more complicated than this. For example, imagine if

<Perl>
tie %Location, 'Tie::DBI';
</Perl>

I could possibly do :

if (tied %Location) {
[...]
}

And try and generate a correct dumper of the internal/private data
structure underlying the tied object, but there are no guarantees that
when you'll restore it back it'll work correctly. And to generate code
that can be eval'ed back, you can just say:

Re-tie %Location with class 'Tie::DBI' using this { 'foo' => 'bar' } as
the untied object... Unless you call TIEHASH once again, and cause the
class to re-tie, but then how do you reinject it the right data.

I don't know if I am missing something terribly simple, 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Patch mp2] Test tied %Location in sections

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Thu, 2004-03-25 at 15:23 -0800, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > On Thu, 2004-03-25 at 13:30 -0800, Stas Bekman wrote:
> > 
> >>Philippe M. Chiasson wrote:
> >>
> >>
> >>>>>Only problem I
> >>>>>can think of is that if you use PerlSections->dump, your hash will be
> >>>>>dumped as a hash, not seeing the tie magic. So next time around, if you
> >>>>>load your dumped <Perl> configuration, you'll experience hash ordering
> >>>>>trouble once again.
> >>>>
> >>>>why can't we keep the tiedness?
> >>>
> >>>
> >>>Well, how are you supposed to correctly dump a tie'd object so it can be
> >>>restored by an eval ?
> >>
> >>simply. if it's tied(), you know which class it was tied into. so when you 
> >>dump it, add the tie directive to tie it back to the class it was tied to in 
> >>first place. Or just use Storable?
> > 
> > 
> > It's actually a lot more complicated than this. For example, imagine if
> > 
> > <Perl>
> > tie %Location, 'Tie::DBI';
> > </Perl>
> > 
> > I could possibly do :
> > 
> > if (tied %Location) {
> > 	[...]
> > }
> > 
> > And try and generate a correct dumper of the internal/private data
> > structure underlying the tied object, but there are no guarantees that
> > when you'll restore it back it'll work correctly. And to generate code
> > that can be eval'ed back, you can just say:
> > 
> > Re-tie %Location with class 'Tie::DBI' using this { 'foo' => 'bar' } as
> > the untied object... Unless you call TIEHASH once again, and cause the
> > class to re-tie, but then how do you reinject it the right data.
> > 
> > I don't know if I am missing something terribly simple, but the only
> > think I can think of is detecting tied %Location and screaming "Bad
> > boy!" if ->dump is called...
> 
> Hmm, what I was suggestion is that if the source was:
> 
>   tie %Location, Foo;
>   %Location = (...);
> 
> the dump will be exactly that:
> 
>   tie %Location, Foo;
>   %Location = (...);
> 
> preserving the order. How does Storable deal with it?

After investigating a bit more, Data::Dumper certainly doesn't see tied
magic, but apparently Storable does :

package Foo;
use Tie::Hash;
use Storable;
use base qw(Tie::StdHash);

tie %L, 'Foo';

my $clone = Storable::thaw(Storable::freeze(\%L));

print tied(%$clone) ? "TIED" : "NOT TIED";
__END__

Does preserve TIED'edness.

I'll look into how Storable does it shortly and hopefully find something
usefull to steal.


> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Patch mp2] Test tied %Location in sections

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> On Thu, 2004-03-25 at 13:30 -0800, Stas Bekman wrote:
> 
>>Philippe M. Chiasson wrote:
>>
>>
>>>>>Only problem I
>>>>>can think of is that if you use PerlSections->dump, your hash will be
>>>>>dumped as a hash, not seeing the tie magic. So next time around, if you
>>>>>load your dumped <Perl> configuration, you'll experience hash ordering
>>>>>trouble once again.
>>>>
>>>>why can't we keep the tiedness?
>>>
>>>
>>>Well, how are you supposed to correctly dump a tie'd object so it can be
>>>restored by an eval ?
>>
>>simply. if it's tied(), you know which class it was tied into. so when you 
>>dump it, add the tie directive to tie it back to the class it was tied to in 
>>first place. Or just use Storable?
> 
> 
> It's actually a lot more complicated than this. For example, imagine if
> 
> <Perl>
> tie %Location, 'Tie::DBI';
> </Perl>
> 
> I could possibly do :
> 
> if (tied %Location) {
> 	[...]
> }
> 
> And try and generate a correct dumper of the internal/private data
> structure underlying the tied object, but there are no guarantees that
> when you'll restore it back it'll work correctly. And to generate code
> that can be eval'ed back, you can just say:
> 
> Re-tie %Location with class 'Tie::DBI' using this { 'foo' => 'bar' } as
> the untied object... Unless you call TIEHASH once again, and cause the
> class to re-tie, but then how do you reinject it the right data.
> 
> I don't know if I am missing something terribly simple, but the only
> think I can think of is detecting tied %Location and screaming "Bad
> boy!" if ->dump is called...

Hmm, what I was suggestion is that if the source was:

  tie %Location, Foo;
  %Location = (...);

the dump will be exactly that:

  tie %Location, Foo;
  %Location = (...);

preserving the order. How does Storable deal with it?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Patch mp2] Test tied %Location in sections

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Thu, 2004-03-25 at 13:30 -0800, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> 
> >>>Only problem I
> >>>can think of is that if you use PerlSections->dump, your hash will be
> >>>dumped as a hash, not seeing the tie magic. So next time around, if you
> >>>load your dumped <Perl> configuration, you'll experience hash ordering
> >>>trouble once again.
> >>
> >>why can't we keep the tiedness?
> > 
> > 
> > Well, how are you supposed to correctly dump a tie'd object so it can be
> > restored by an eval ?
> 
> simply. if it's tied(), you know which class it was tied into. so when you 
> dump it, add the tie directive to tie it back to the class it was tied to in 
> first place. Or just use Storable?

It's actually a lot more complicated than this. For example, imagine if

<Perl>
tie %Location, 'Tie::DBI';
</Perl>

I could possibly do :

if (tied %Location) {
	[...]
}

And try and generate a correct dumper of the internal/private data
structure underlying the tied object, but there are no guarantees that
when you'll restore it back it'll work correctly. And to generate code
that can be eval'ed back, you can just say:

Re-tie %Location with class 'Tie::DBI' using this { 'foo' => 'bar' } as
the untied object... Unless you call TIEHASH once again, and cause the
class to re-tie, but then how do you reinject it the right data.

I don't know if I am missing something terribly simple, but the only
think I can think of is detecting tied %Location and screaming "Bad
boy!" if ->dump is called...
 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Patch mp2] Test tied %Location in sections

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:

>>>Only problem I
>>>can think of is that if you use PerlSections->dump, your hash will be
>>>dumped as a hash, not seeing the tie magic. So next time around, if you
>>>load your dumped <Perl> configuration, you'll experience hash ordering
>>>trouble once again.
>>
>>why can't we keep the tiedness?
> 
> 
> Well, how are you supposed to correctly dump a tie'd object so it can be
> restored by an eval ?

simply. if it's tied(), you know which class it was tied into. so when you 
dump it, add the tie directive to tie it back to the class it was tied to in 
first place. Or just use Storable?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Patch mp2] Test tied %Location in sections

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Thu, 2004-03-25 at 13:09 -0800, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > As we discussed, instead of trying to use Tie::IxHash behind the scenes
> > to order %Location blocks and such, we will recommend users to use Tie::
> > * for themselves like so:
> > 
> > <Perl>
> >  tie %Location, "My::Tie";
> > 
> > </Perl>
> > 
> > So, until I get around updating the documentation, I've at least tested
> > that tied %Hashes in <Perl> sections do behave proprely. 
> 
> +1 after the usual request to fix indentation (perl code in the conf file) ;)

Will take care of this, as my identation skills are weakened ;-)

> 
> > Only problem I
> > can think of is that if you use PerlSections->dump, your hash will be
> > dumped as a hash, not seeing the tie magic. So next time around, if you
> > load your dumped <Perl> configuration, you'll experience hash ordering
> > trouble once again.
> 
> why can't we keep the tiedness?

Well, how are you supposed to correctly dump a tie'd object so it can be
restored by an eval ?

> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Patch mp2] Test tied %Location in sections

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> As we discussed, instead of trying to use Tie::IxHash behind the scenes
> to order %Location blocks and such, we will recommend users to use Tie::
> * for themselves like so:
> 
> <Perl>
>  tie %Location, "My::Tie";
> 
> </Perl>
> 
> So, until I get around updating the documentation, I've at least tested
> that tied %Hashes in <Perl> sections do behave proprely. 

+1 after the usual request to fix indentation (perl code in the conf file) ;)

> Only problem I
> can think of is that if you use PerlSections->dump, your hash will be
> dumped as a hash, not seeing the tie magic. So next time around, if you
> load your dumped <Perl> configuration, you'll experience hash ordering
> trouble once again.

why can't we keep the tiedness?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org