[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

How to efficiently wrap similar objects?

Asked by kandura in Perl Programming Language

Tags: rai, xml

Hi,

I'm currently writing an application that handles RSS and Atom feeds. I have a bit of a conceptual problem though, and that is how I should encapsulate the different parsers, and the objects they emit, so that I can present a unified interface to the rest of my program.

Is there a common solution to this type of problem? Is there an elegant way to wrap similar-but-differing parsers that emit similar objects?

I've been reading a lot on Design Patterns, OO and such stuff lately, but all that is either too abstract, or I can't see how to apply it to this situation.

I'd appreciate tips, pointers to tutorials or CPAN modules that could help me in this.

Here's a more detailed description of the situation I'm in.
There doesn't exist one single parser for the different kinds of feeds, so I'm using XML::RAI to parse RSS feeds, and XML::Atom::Feed to parse Atom feeds. My own "parse" routine is now an if/else tree like this:

sub parse {
    my ($xml, $type) = @_;
   
    if($type eq 'RSS') {
        return parse_rss($xml);
    }
    elsif($type eq 'ATOM') {
        return parse_atom($xml);
    }
    else {
    # we don't know what this is,
    # so we try each in turn
        return parse_atom($xml) || parse_rss($xml);
    }
}

sub parse_atom {
    my $xml = shift;
    my $parser = XML::Atom::Feed->new(\$xml);
    # lots of code specific to XML::Atom::Feed
}

sub parse_rss {
    my $xml = shift;
    my $parser = XML::RAI->parse($xml);
    # lots of code specific to XML::RAI
}

Ugly. Clumsy.

Then there's the issue with the objects these parsers emit: each one returns their own specific Feed object; each has a method to get at the items, which are objects specific to each parser. I'd like to be able to represent those in a unified way, so that my application doesn't have to worry about the underlying types.
Right now I have resorted to making my own Feed and FeedItem objects (using Class::Accessor), which I populate in the parse_atom and parse_rss subs. But this feels cumbersome, and it looks ugly to me.

Thanks!
[+][-]03/07/05 09:31 AM, ID: 13478447Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Perl Programming Language
Tags: rai, xml
Sign Up Now!
Solution Provided By: davorg
Participating Experts: 2
Solution Grade: A
 
[+][-]03/07/05 10:24 AM, ID: 13479045Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03/07/05 04:37 PM, ID: 13482470Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/26/05 02:16 PM, ID: 13637402Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/12/05 07:56 PM, ID: 13992985Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07/01/05 09:15 AM, ID: 14349140Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07/05/05 02:59 AM, ID: 14367331Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89