You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by David Wheeler <da...@kineticode.com> on 2003/09/01 07:30:40 UTC
Apache::FakeTable
Hi All,
I've created a pure Perl implementation of the Apache::Table class and
uploaded it to CPAN.
http://search.cpan.org/dist/Apache-FakeTable/
I'd be interested in your comments and feedback before I put out a more
generalized announcement. Information on how to reproduce
Apache::Table's treatment of C<each> would be especially welcome.
Regards,
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> seriously, though. for all the effort people put into stuff like
> Apache::FakeRequest, I would have thought the time better spent learning
> Apache-Test, which essentially not only makes these classes obsolete,
> but also encourages good programming practices (namely, writing tests
> instead of a one-off development process).
Agreed. But I suppose that there is a place for both. e.g. I can think of
someone hacking some code on their mobile, and has no apache installed (but
does have perl ;)
__________________________________________________________________
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: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Tuesday, September 2, 2003, at 08:58 PM, Stas Bekman wrote:
> It's probably worth mentioning on the modperl list. Care to post a
> note? Or ask the author to do that?
I asked him to do it.
D
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
David Wheeler wrote:
> On Tuesday, September 2, 2003, at 05:33 PM, Stas Bekman wrote:
>
>> That sounds not so good. Unless you had a typo and it should have been
>> Apache::Emulator in first place.
>
>
> Typo, sorry.
;)
It's probably worth mentioning on the modperl list. Care to post a note? Or
ask the author to do that?
__________________________________________________________________
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: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Tuesday, September 2, 2003, at 05:33 PM, Stas Bekman wrote:
> That sounds not so good. Unless you had a typo and it should have been
> Apache::Emulator in first place.
Typo, sorry.
D
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
David Wheeler wrote:
> On Tuesday, September 2, 2003, at 12:05 PM, Geoffrey Young wrote:
>
>> david, was there a real driving reason behind Apache::FakeTable that
>> Apache-Test couldn't fill? is there a way we can make A-T better so
>> that you wouldn't need FakeTable?
>
>
> No, I needed it to emulate Apache.pm (and Apache::Request) under CGI
> for Mason.
>
> http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mason/mason/dist/lib/
> HTML/Mason/CGIHandler.pm
>
> Note the new Apache::Emulate module on CPAN, which is trying to do
> something similar.
Hmm, searching for Apache::Emulate,
http://search.cpan.org/search?query=Apache%3A%3AEmulate&mode=all
I have found: Apache::Emulator,
http://search.cpan.org/author/NWETTERS/Apache-Emulator-0.04/lib/Apache/Emulator.pm
That sounds not so good. Unless you had a typo and it should have been
Apache::Emulator in first place.
__________________________________________________________________
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: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Tuesday, September 2, 2003, at 12:05 PM, Geoffrey Young wrote:
> david, was there a real driving reason behind Apache::FakeTable that
> Apache-Test couldn't fill? is there a way we can make A-T better so
> that you wouldn't need FakeTable?
No, I needed it to emulate Apache.pm (and Apache::Request) under CGI
for Mason.
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mason/mason/dist/lib/
HTML/Mason/CGIHandler.pm
Note the new Apache::Emulate module on CPAN, which is trying to do
something similar.
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Stas Bekman wrote:
> David Wheeler wrote:
>
>> On Tuesday, September 2, 2003, at 10:51 AM, Stas Bekman wrote:
>>
>>> This is for mod_perl 1.0, right? In mp2 it's APR::Table and it is
>>> available outside mod_perl (well, it's almost there, still need to
>>> remove a few dependencies on mp symbols).
>>
>>
>>
>> Ah, that's cool. Yes, this is for 1.x.
>
>
> Of course it needs libapr to be installed ;) APR:: classes will be used
> to implement a real Apache::FakeRequestRec (independent of mod_perl)
> once someone will code it.
ahem... :)
isn't it time we advocated Apache-Test over stuff like Fake::Foo?
seriously, though. for all the effort people put into stuff like
Apache::FakeRequest, I would have thought the time better spent learning
Apache-Test, which essentially not only makes these classes obsolete, but
also encourages good programming practices (namely, writing tests instead of
a one-off development process).
david, was there a real driving reason behind Apache::FakeTable that
Apache-Test couldn't fill? is there a way we can make A-T better so that
you wouldn't need FakeTable?
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
Besides, may be the naming isn't right. Since the table is not fake. Apache is
the one that's fake. Same for Apache::FakeRequest. May be the top level
namespace is the one that should be adjusted? ApacheEmulator::Request,
ApacheEmulator::Table, etc.? of course you will probably come up with a better
name, but the point is that we create a new namespace for an Apache emulators.
ApacheEmu::?
__________________________________________________________________
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: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Friday, September 5, 2003, at 11:46 AM, Joe Schaefer wrote:
> If $t references a table consisting of 3 entries:
>
> (foo => 1)
> (foo => 2)
> (foo => 3)
>
> then the docs say that
>
> print "($a => $b)\n" while ($a, $b) = each %$t;
>
> will reproduce the above 3 lines. But what you actually
> get is
>
> (foo => 1)
> (foo => 1)
> (foo => 1)
Ah, this is why testing is so important! Maybe some TODO tests should
be added?
>> Apache::FakeTable apes Apache::Table much more closely now, including
>> its C<each> behavior, as well as C<keys>
>
> Neat.
>
>> and C<values> (the latter being pretty much useless).
>
> Too bad that Apache/APR::Table doesn't get this right. Maybe
> we should have a look at how Matt Sergeant implemented CDB_File,
> since he may have found a way/hack (requires XS) to get each()
> and values() to DTRT with multivalued keys.
I think that this is the same problem as with C<values>, which given
the contents of your table above, this:
print "$_\n" for values %$t;
Would print
1
1
1
Regards,
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Joe Schaefer <jo...@sunstarsys.com>.
David Wheeler <da...@kineticode.com> writes:
> On Friday, September 5, 2003, at 04:58 AM, Joe Schaefer wrote:
>
> > s/FETCH/NEXTKEY/; C<scalar FETCH> always yields the first
> > value of a multivalued key. Unless something has changed
> > recently, C<each() in list context> still doesn't do what
> > the documentation suggests.
>
> What is it supposed to do?
If $t references a table consisting of 3 entries:
(foo => 1)
(foo => 2)
(foo => 3)
then the docs say that
print "($a => $b)\n" while ($a, $b) = each %$t;
will reproduce the above 3 lines. But what you actually
get is
(foo => 1)
(foo => 1)
(foo => 1)
> Apache::FakeTable apes Apache::Table much more closely now, including
> its C<each> behavior, as well as C<keys>
Neat.
> and C<values> (the latter being pretty much useless).
Too bad that Apache/APR::Table doesn't get this right. Maybe
we should have a look at how Matt Sergeant implemented CDB_File,
since he may have found a way/hack (requires XS) to get each()
and values() to DTRT with multivalued keys.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Friday, September 5, 2003, at 04:58 AM, Joe Schaefer wrote:
> s/FETCH/NEXTKEY/; C<scalar FETCH> always yields the first
> value of a multivalued key. Unless something has changed
> recently, C<each() in list context> still doesn't do what
> the documentation suggests.
What is it supposed to do?
Apache::FakeTable apes Apache::Table much more closely now, including
its C<each> behavior, as well as C<keys> and C<values> (the latter
being pretty much useless).
Cheers,
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Hopefully you can read C without understanding it ;) All it does is
> having a counter which tracks where it is inside the hash entry's
> list. so when you call FETCH it uses that index to get the right value.
^^^^^
s/FETCH/NEXTKEY/; C<scalar FETCH> always yields the first
value of a multivalued key. Unless something has changed
recently, C<each() in list context> still doesn't do what
the documentation suggests.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Tuesday, September 2, 2003, at 03:08 PM, Stas Bekman wrote:
> Hopefully you can read C without understanding it ;) All it does is
> having a counter which tracks where it is inside the hash entry's
> list. so when you call FETCH it uses that index to get the right > value.
Managed to do it without reading it. :-) I also did some
experimentation and made a few other changes to make it behave more
like Apache::Table does. I've now uploaded Apache::FakeTable 0.02 to
CPAN. Here are the changes:
0.02 Thu Sep 4 05:32:22 2003
- Fixed behavior of each to match that of Apache::Table. It will
now return multiple key/value pairs for a single key that has
multiple values.
- Changed behavior of new() to require an Apache object as its
first object to bring it more in line with the behavior of
Apache::Table::new.
- Assigning a value of undef no longer deletes the key from the
table, but goes ahead and assigns it. When warnings are
enabled,
this will cause Apache::FakeTable to issue a "Use of
uninitialized value in null operation" warning.
- The merge() method will now only merge the new value with the
first value when a key has multiple existing values. It also
now
uses a comma and a space to separate the values, instead of
just
a comma.
At this point, I think it's pretty damn close. Bug reports welcome. If
folks decide that they'd like to use a different namespace for the
fake/emulate modules, I'll be happy to relocate this module.
Cheers,
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
>> Yes, so you need to change the NEXTKEY implementation to track the
>> index by yourself. e.g., look at the C/XS implementation?
>
>
> Maybe. Will have to see where I put my C/XS chops. Oh wait, I don't
> really know C/XS! ;-)
Hopefully you can read C without understanding it ;) All it does is having a
counter which tracks where it is inside the hash entry's list. so when you
call FETCH it uses that index to get the right value.
__________________________________________________________________
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: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Tuesday, September 2, 2003, at 11:58 AM, Stas Bekman wrote:
> Of course it needs libapr to be installed ;) APR:: classes will be
> used to implement a real Apache::FakeRequestRec (independent of
> mod_perl) once someone will code it.
Ah, excellent.
> Yes, so you need to change the NEXTKEY implementation to track the
> index by yourself. e.g., look at the C/XS implementation?
Maybe. Will have to see where I put my C/XS chops. Oh wait, I don't
really know C/XS! ;-)
I'll put it on my list. Meanwhile, do() is a lot more efficient,
anyway, and it will pass all of the values in the table for a given key
with that key to each call to the code reference.
Cheers,
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
David Wheeler wrote:
> On Tuesday, September 2, 2003, at 10:51 AM, Stas Bekman wrote:
>
>> This is for mod_perl 1.0, right? In mp2 it's APR::Table and it is
>> available outside mod_perl (well, it's almost there, still need to
>> remove a few dependencies on mp symbols).
>
>
> Ah, that's cool. Yes, this is for 1.x.
Of course it needs libapr to be installed ;) APR:: classes will be used to
implement a real Apache::FakeRequestRec (independent of mod_perl) once someone
will code it.
>> You probably need to implement it internally as a hash of lists and
>> adjust the NEXTKEY method to handle that.
>
>
> It _is_ a hash of array references (or rather a hash of arrays of
> arrays), but NEXTKEY, AFAIK, returns a single scalar value, not a list
> of key/value pairs.
Yes, so you need to change the NEXTKEY implementation to track the index by
yourself. e.g., look at the C/XS implementation?
__________________________________________________________________
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: Apache::FakeTable
Posted by David Wheeler <da...@kineticode.com>.
On Tuesday, September 2, 2003, at 10:51 AM, Stas Bekman wrote:
> This is for mod_perl 1.0, right? In mp2 it's APR::Table and it is
> available outside mod_perl (well, it's almost there, still need to
> remove a few dependencies on mp symbols).
Ah, that's cool. Yes, this is for 1.x.
> You probably need to implement it internally as a hash of lists and
> adjust the NEXTKEY method to handle that.
It _is_ a hash of array references (or rather a hash of arrays of
arrays), but NEXTKEY, AFAIK, returns a single scalar value, not a list
of key/value pairs.
Regards,
David
--
David Wheeler AIM: dwTheory
david@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Theory@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Apache::FakeTable
Posted by Stas Bekman <st...@stason.org>.
David Wheeler wrote:
> Hi All,
>
> I've created a pure Perl implementation of the Apache::Table class and
> uploaded it to CPAN.
>
> http://search.cpan.org/dist/Apache-FakeTable/
>
> I'd be interested in your comments and feedback before I put out a more
> generalized announcement.
This is for mod_perl 1.0, right? In mp2 it's APR::Table and it is available
outside mod_perl (well, it's almost there, still need to remove a few
dependencies on mp symbols).
> Information on how to reproduce
> Apache::Table's treatment of C<each> would be especially welcome.
You probably need to implement it internally as a hash of lists and adjust the
NEXTKEY method to handle that.
__________________________________________________________________
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