For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2005 > cross-eyed object problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cross-eyed object problem
Tom Allison

2005-07-30, 9:59 pm

I'm stuck.... I need an extra pair of eyes.

I have an object that uses MIME::Parser to create a MIME::Entity from a
message string.

I have a test script that loads the message string and passes it to the
object to parse. It dies on one of 10 messages.

Yet, if I pull the parser code out of the object, it works great....

Here is my test script:
27 {
28 my $parser = new MIME::Parser;
29 $parser->ignore_errors(1);
30 $parser->output_dir("/tmp");
31 $parser->tmp_recycling(1);
32 $parser->extract_uuencode(1);
33 my $entity = eval { $parser->parse_data($message) };
34 isa_ok($entity, 'MIME::Entity');
35 $parser->filer->purge;
36 }
37 my $wm = WebMIME->new( message => $message );

Line 37 fails.....

Here is my object script:
sub new
{
my %args = (
output_dir => '/tmp',
tmp_recycling => 1,
extract_uuencode => 1,
ignore_errors => 1
);
my $class = shift;
%args = @_;

my $parser = new MIME::Parser;
$parser->ignore_errors($args{ignore_errors});
$parser->output_dir($args{output_dir});
$parser->tmp_recycling($args{tmp_recycling});
$parser-> extract_uuencode($args{extract_uuencode}
);

my $entity = eval { $parser->parse_data($args{message}) };
if ($@) {
cluck "Problem parsing Entity: $!";
my $results = $parser->results;
my $decapitated = $parser->last_head;
warn $results;
warn $decapitated,"\n";
}
[...]
)

I'm just not sure what I could possibly need to do....
Tom Allison

2005-07-30, 9:59 pm

Tom Allison wrote:
> I'm stuck.... I need an extra pair of eyes.


> Here is my object script:
> sub new
> {
> my %args = (
> output_dir => '/tmp',
> tmp_recycling => 1,
> extract_uuencode => 1,
> ignore_errors => 1
> );
> my $class = shift;
> %args = @_;
>


Sometimes it helps to walk away...

I over-write %args....

better to try:
my %a = @_;
%args = (%args, %a);

But I'm not sure that this is the cleanest.
Tom Allison

2005-07-31, 3:59 am

Tom Allison wrote:
> I'm stuck.... I need an extra pair of eyes.
>


It helps to walk away for a while

> Here is my object script:
> sub new
> {
> my %args = (
> output_dir => '/tmp',
> tmp_recycling => 1,
> extract_uuencode => 1,
> ignore_errors => 1
> );
> my $class = shift;
> %args = @_;
>


I over write %args...
change to
my %a = @_;
%args = (%args, %a);

But I'm not sure that this is as clean as it could be.
Tom Allison

2005-07-31, 8:59 am


>
> Here is my object script:
> sub new
> {
> my %args = (
> output_dir => '/tmp',
> tmp_recycling => 1,
> extract_uuencode => 1,
> ignore_errors => 1
> );
> my $class = shift;
> %args = @_;
>



Ugh!!!

should be
my %a = @_;
%args = (%args, %a);

But it's all better now.
Paul Johnson

2005-07-31, 8:59 am

On Sat, Jul 30, 2005 at 11:03:09PM -0400, Tom Allison wrote:

> Tom Allison wrote:
>
> I over write %args...
> change to
> my %a = @_;
> %args = (%args, %a);
>
> But I'm not sure that this is as clean as it could be.


I'd probably do something like:

my %args = (
output_dir => '/tmp',
tmp_recycling => 1,
extract_uuencode => 1,
ignore_errors => 1,
@_
);

A lot of my constructors look similar to this.

--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com