Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Entities.pm - How does decode_entities work?

Reply
Thread Tools

Entities.pm - How does decode_entities work?

 
 
Dave Saville
Guest
Posts: n/a
 
      12-16-2010
I needed to massage some text to put in a web page. I started out with
some s/!/!;/g; type lines and then twigged that perl would most
likely have a module to do it. HTML::Entities.pm. This works fine, but
I then wanted to see *how* it did it.

Having found the module, Entities.pm, I copied it to a tmp directory
and modified the start of my test script from

use HTML::Entities;

to

use lib '.';
use Entities;

I then started sticking in print statements and eventually worked out
how the encode worked. I then tried to do the same with the decode
only to get an error:

Undefined subroutine &Entities::decode_entities called at try.pl line
18.

I then see that the sub line in Entities.pm is sub
decode_entities_old. OK so it's not amazing it could not find it. But
the question is how on earth does it work when the use HTML::Entities
is in effect? Which it does. I ran a search down the entire perl tree
looking for any file with a "sub decode_entities" in it and
Entities.pm is the only file and then it is decode_entities_old. So
how *does* it work?

Is there some way to find out where perl is getting a particular
routine from - rather like the *nix command line "which"?

TIA

--
Regards
Dave Saville
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      12-16-2010
>>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

DS> I needed to massage some text to put in a web page. I started out with
DS> some s/!/!;/g; type lines and then twigged that perl would most
DS> likely have a module to do it. HTML::Entities.pm. This works fine, but
DS> I then wanted to see *how* it did it.

DS> Having found the module, Entities.pm, I copied it to a tmp directory
DS> and modified the start of my test script from

DS> use HTML::Entities;

DS> to

DS> use lib '.';
DS> use Entities;

what happened to the HTTP:: part? why did you think you could drop it?


DS> I then started sticking in print statements and eventually worked out
DS> how the encode worked. I then tried to do the same with the decode
DS> only to get an error:

DS> Undefined subroutine &Entities::decode_entities called at try.pl line
DS> 18.

you broke its exporting.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      12-16-2010
>>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

DS> I then see that the sub line in Entities.pm is sub
DS> decode_entities_old. OK so it's not amazing it could not find it. But
DS> the question is how on earth does it work when the use HTML::Entities
DS> is in effect? Which it does. I ran a search down the entire perl tree
DS> looking for any file with a "sub decode_entities" in it and
DS> Entities.pm is the only file and then it is decode_entities_old. So
DS> how *does* it work?

DS> Is there some way to find out where perl is getting a particular
DS> routine from - rather like the *nix command line "which"?

if you read the source and look for decode_entities there is a comment
which says where it is located.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Dave Saville
Guest
Posts: n/a
 
      12-16-2010
On Thu, 16 Dec 2010 17:44:02 UTC, "Uri Guttman" <(E-Mail Removed)>
wrote:

> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

>
> DS> I needed to massage some text to put in a web page. I started out with
> DS> some s/!/!;/g; type lines and then twigged that perl would most
> DS> likely have a module to do it. HTML::Entities.pm. This works fine, but
> DS> I then wanted to see *how* it did it.
>
> DS> Having found the module, Entities.pm, I copied it to a tmp directory
> DS> and modified the start of my test script from
>
> DS> use HTML::Entities;
>
> DS> to
>
> DS> use lib '.';
> DS> use Entities;
>
> what happened to the HTTP:: part? why did you think you could drop it?
>


Er, what HTTP part? Did you mean the HTML part? I dropped it because
my test version was not in an HTML directory. It was in the same
directory as the test code.


>
> DS> I then started sticking in print statements and eventually worked out
> DS> how the encode worked. I then tried to do the same with the decode
> DS> only to get an error:
>
> DS> Undefined subroutine &Entities::decode_entities called at try.pl line
> DS> 18.
>
> you broke its exporting.
>


How? It can find encode_entities fine. Why didn't that break? The
EXPORT lines don't mention the higher HTML layer except in the package
header and I removed that portion of it.

--
Regards
Dave Saville
 
Reply With Quote
 
Dave Saville
Guest
Posts: n/a
 
      12-16-2010
On Thu, 16 Dec 2010 17:45:55 UTC, "Uri Guttman" <(E-Mail Removed)>
wrote:

> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

>
> DS> I then see that the sub line in Entities.pm is sub
> DS> decode_entities_old. OK so it's not amazing it could not find it. But
> DS> the question is how on earth does it work when the use HTML::Entities
> DS> is in effect? Which it does. I ran a search down the entire perl tree
> DS> looking for any file with a "sub decode_entities" in it and
> DS> Entities.pm is the only file and then it is decode_entities_old. So
> DS> how *does* it work?
>
> DS> Is there some way to find out where perl is getting a particular
> DS> routine from - rather like the *nix command line "which"?
>
> if you read the source and look for decode_entities there is a comment
> which says where it is located.


Yes I see - a require for HTML:arser - But Parser does not have a
decode_entities so I repeat *how* does the routine reference get
resolved. I do not understand.

--
Regards
Dave Saville
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      12-16-2010
>>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

DS> On Thu, 16 Dec 2010 17:44:02 UTC, "Uri Guttman" <(E-Mail Removed)>
DS> wrote:

>> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

>>

DS> I needed to massage some text to put in a web page. I started out with
DS> some s/!/!;/g; type lines and then twigged that perl would most
DS> likely have a module to do it. HTML::Entities.pm. This works fine, but
DS> I then wanted to see *how* it did it.
>>

DS> Having found the module, Entities.pm, I copied it to a tmp directory
DS> and modified the start of my test script from
>>

DS> use HTML::Entities;
>>

DS> to
>>

DS> use lib '.';
DS> use Entities;
>>
>> what happened to the HTTP:: part? why did you think you could drop it?
>>


DS> Er, what HTTP part? Did you mean the HTML part? I dropped it because
DS> my test version was not in an HTML directory. It was in the same
DS> directory as the test code.


>>

DS> I then started sticking in print statements and eventually worked out
DS> how the encode worked. I then tried to do the same with the decode
DS> only to get an error:
>>

DS> Undefined subroutine &Entities::decode_entities called at try.pl line
DS> 18.
>>
>> you broke its exporting.
>>


DS> How? It can find encode_entities fine. Why didn't that break? The
DS> EXPORT lines don't mention the higher HTML layer except in the package
DS> header and I removed that portion of it.

because you used only Entities. rtfm on how use works. it first finds
and loads the module you requested (that worked). but then it calls the
import method on the class name passed to use. the module's class is
HTML::Entities but you used only Entities so it called
Entities->import() which doesn't exist and so nothing got exported.

you must use the proper class name when using a module to get
exporting.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      12-16-2010
>>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

DS> On Thu, 16 Dec 2010 17:45:55 UTC, "Uri Guttman" <(E-Mail Removed)>
DS> wrote:

>> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

>>

DS> I then see that the sub line in Entities.pm is sub
DS> decode_entities_old. OK so it's not amazing it could not find it. But
DS> the question is how on earth does it work when the use HTML::Entities
DS> is in effect? Which it does. I ran a search down the entire perl tree
DS> looking for any file with a "sub decode_entities" in it and
DS> Entities.pm is the only file and then it is decode_entities_old. So
DS> how *does* it work?
>>

DS> Is there some way to find out where perl is getting a particular
DS> routine from - rather like the *nix command line "which"?
>>
>> if you read the source and look for decode_entities there is a comment
>> which says where it is located.


DS> Yes I see - a require for HTML:arser - But Parser does not have a
DS> decode_entities so I repeat *how* does the routine reference get
DS> resolved. I do not understand.

it is in XS as the comment says. so it is somewhere else in the build
for HTML:arser. you need to explore deeper. and it will be in c for
speed.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Xho Jingleheimerschmidt
Guest
Posts: n/a
 
      12-17-2010
Dave Saville wrote:
> On Thu, 16 Dec 2010 17:45:55 UTC, "Uri Guttman" <(E-Mail Removed)>
> wrote:
>
>>>>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

>> DS> I then see that the sub line in Entities.pm is sub
>> DS> decode_entities_old. OK so it's not amazing it could not find it. But
>> DS> the question is how on earth does it work when the use HTML::Entities
>> DS> is in effect? Which it does. I ran a search down the entire perl tree
>> DS> looking for any file with a "sub decode_entities" in it and
>> DS> Entities.pm is the only file and then it is decode_entities_old. So
>> DS> how *does* it work?
>>
>> DS> Is there some way to find out where perl is getting a particular
>> DS> routine from - rather like the *nix command line "which"?
>>
>> if you read the source and look for decode_entities there is a comment
>> which says where it is located.

>
> Yes I see - a require for HTML:arser - But Parser does not have a
> decode_entities so I repeat *how* does the routine reference get
> resolved. I do not understand.


The module is not pure Perl. It links in a C library. That is what
XSLoader does.

Xho
 
Reply With Quote
 
Dave Saville
Guest
Posts: n/a
 
      12-17-2010
On Thu, 16 Dec 2010 23:40:01 UTC, "Uri Guttman" <(E-Mail Removed)>
wrote:

> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:

>
> DS> On Thu, 16 Dec 2010 17:44:02 UTC, "Uri Guttman" <(E-Mail Removed)>
> DS> wrote:
>
> >> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:
> >>

> DS> I needed to massage some text to put in a web page. I started out with
> DS> some s/!/!;/g; type lines and then twigged that perl would most
> DS> likely have a module to do it. HTML::Entities.pm. This works fine, but
> DS> I then wanted to see *how* it did it.
> >>

> DS> Having found the module, Entities.pm, I copied it to a tmp directory
> DS> and modified the start of my test script from
> >>

> DS> use HTML::Entities;
> >>

> DS> to
> >>

> DS> use lib '.';
> DS> use Entities;
> >>
> >> what happened to the HTTP:: part? why did you think you could drop it?
> >>

>
> DS> Er, what HTTP part? Did you mean the HTML part? I dropped it because
> DS> my test version was not in an HTML directory. It was in the same
> DS> directory as the test code.
>
>
> >>

> DS> I then started sticking in print statements and eventually worked out
> DS> how the encode worked. I then tried to do the same with the decode
> DS> only to get an error:
> >>

> DS> Undefined subroutine &Entities::decode_entities called at try.pl line
> DS> 18.
> >>
> >> you broke its exporting.
> >>

>
> DS> How? It can find encode_entities fine. Why didn't that break? The
> DS> EXPORT lines don't mention the higher HTML layer except in the package
> DS> header and I removed that portion of it.
>
> because you used only Entities. rtfm on how use works. it first finds
> and loads the module you requested (that worked). but then it calls the
> import method on the class name passed to use. the module's class is
> HTML::Entities but you used only Entities so it called
> Entities->import() which doesn't exist and so nothing got exported.
>
> you must use the proper class name when using a module to get
> exporting.
>


Please read what I wrote.

Calling script has use "Entities;"

Entities.pm has "package Entities;"

HTML:: is not mentioned anywhere else.


--
Regards
Dave Saville
 
Reply With Quote
 
Dave Saville
Guest
Posts: n/a
 
      12-17-2010
On Thu, 16 Dec 2010 23:40:51 UTC, "Uri Guttman" <(E-Mail Removed)>
wrote:

> >>>>> "DS" == Dave Saville <(E-Mail Removed)> writes:


<snip>

> DS> Yes I see - a require for HTML:arser - But Parser does not have a
> DS> decode_entities so I repeat *how* does the routine reference get
> DS> resolved. I do not understand.
>
> it is in XS as the comment says. so it is somewhere else in the build
> for HTML:arser. you need to explore deeper. and it will be in c for
> speed.
>


OK found it thanks. You are right it's in c - never thought to look in
other than .pm files


--
Regards
Dave Saville
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
CS0234 Global does not exist ... but it genuinely does Bill Johnson ASP .Net 0 07-08-2005 06:34 PM
Does no one else think microsoft does a poor job? =?Utf-8?B?SmVyZW15IEx1bmRncmVu?= Wireless Networking 2 11-20-2004 12:17 AM
decode_entities possible bug? Richard Bell Perl Misc 14 06-01-2004 08:05 PM
decode_entities possible bug? Richard Bell Perl 6 05-31-2004 08:48 PM



Advertisments