Hi Monks!

I'm having a slight understanding problem pertaining the use of external modules, packages and the scope of objects/functions (not really sure what the right terms are, so i'm just putting everything under the same hood).

Basically, i want to use package XML::LibXML. So what I do is write use XML::LibXML; at the beginning of the file. So far so good.

Then I want to call the new() function to create a new parser, and I can fully understand the need for the XML::LibXML::new() notation.

Then I want to call function parse_html_file from this object. I'd have expected the interpreter to be able to recognize that, using an object of type XML::LibXML::Parser, $xmlparser->parse_html_file( $file ) refers to this function. However, when I write it this way, then I get an error:
Can't locate object method "parse_html_file" via package "main" at tes +txml.pl line 25.
But well, let's be well-mannered and write $xmlparser->XML::LibXML::parse_html_file( $file ). Oh joy, the error has vanished! And has been replaced by another one:
Can't locate object method "_init_callbacks" via package "main" at /us +r/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi/XML/LibXML.pm +line 823.
which I now fail to understand. I've been trying to add some XML::LibXML at various places that might have seemed logical to me, needless to say without any luck.

Incidentally, executing the following script with the -w option raises some warnings from LibXML.pm, but I assume they don't have any part in my current problem?
#!/usr/bin/perl -w use strict; use XML::LibXML; my $file = shift; my $xmlparser; my $doc; $xmlparser = XML::LibXML::new(); $doc = $xmlparser->XML::LibXML::parse_html_file( $file ) or die "unabl +e to parse $file: $@";
And here's the output:
enigma:~/projects/pt] pagod% perl testxml1.pl Use of uninitialized value $class in bless at /usr/lib/perl5/site_perl +/5.10.0/x86_64-linux-thread-multi/XML/LibXML.pm line 191. Explicit blessing to '' (assuming package main) at /usr/lib/perl5/site +_perl/5.10.0/x86_64-linux-thread-multi/XML/LibXML.pm line 191. Can't locate object method "_init_callbacks" via package "main" at /us +r/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi/XML/LibXML.pm +line 823. [enigma:~/projects/pt] pagod%
So I guess these problems are solely due to my lack of experience with using modules and packages and stuff. So perhaps someone might like to explain to me what I'm doing wrong and how I could do it right?

Thanx a lot in advance!

Pagod

In reply to scope and packages by pagod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.