Skip Menu |

This queue is for tickets about the WebService-Blogger CPAN distribution.

Report information
The Basics
Id: 64436
Status: resolved
Priority: 0/
Queue: WebService-Blogger

People
Owner: Nobody in particular
Requestors: AJGOUGH [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.14
Fixed in: (no value)



Subject: cannot create object, claims to not have password attribute
my $blogger = WebService::Blogger->new( 'login_id' => 'valid email', 'password' => 'valid password', ); fails with: C:\Users\alex\Documents\alexwork\perl>perl scrape.pl Attribute (password) is required at scrape.pl line 10 If I modify the attributes of the object to be rw and make the class mutable, then instead this fails with: C:\Users\alex\Documents\alexwork\perl>perl scrape_useperl.pl Attribute (password) is required at C:/strawberry/perl/site/lib/Class/MOP/Class.pm line 603 Class::MOP::Class::_construct_instance('Moose::Meta::Class=HASH(0x30e7f4 c)', undef) called at C:/strawberry/perl/site/lib/Class/ Class.pm line 576 Class::MOP::Class::new_object('Moose::Meta::Class=HASH(0x30e7f4c)', undef) called at C:/strawberry/perl/site/lib/Moose/Meta/Clas line 256 Moose::Meta::Class::new_object('Moose::Meta::Class=HASH(0x30e7f4c)', undef) called at C:/strawberry/perl/site/lib/Moose/Object.p ne 26 Moose::Object::new('WebService::Blogger', 'login_id', 'valid user', 'password', 'valid password') called at scrape.pl line 10 So this might be a problem with Moose, but I'm not so much into that.
On Mon Jan 03 19:11:47 2011, AJGOUGH wrote: Show quoted text
> my $blogger = WebService::Blogger->new( > 'login_id' => 'valid email', > 'password' => 'valid password', > );
This works fine if I use the ~/.file method to specify these.
As I pointed out on Stack Overflow (http://stackoverflow.com/questions/4189285/perl-webserviceblogger), the BUILDARGS method is buggy. Despite the documentation claiming that you can say my $blogger = WebService::Blogger->new( 'login_id' => 'valid email', 'password' => 'valid password' ); it doesn't actually work. In fact you *must* put your credentials in ~/.www_blogger_rc. The BUILDARGS method needs to look for parameters passed to it and only read the file if login_id & password aren't given.
From: sysoevd [...] gmail.com
I wrote some small patch to fix this issue.
Subject: WebService-Blogger-0.14.patch
--- WebService-Blogger-0.14/lib/WebService/Blogger.pm 2010-09-18 17:42:46.000000000 +0400 +++ WebService-Blogger-0.14.new/lib/WebService/Blogger.pm 2011-11-13 05:27:39.000000000 +0400 @@ -39,28 +39,39 @@ sub BUILDARGS { ## Loads credentials from ~/.www_blogger_rc + my $class = shift; - - # See if there's a file with login credentials and return if not. - my $creds_file_name = $class->creds_file_name; - return unless -s $creds_file_name; - - # Don't allow it to be readable or writable by others, for security reasons. - die "$creds_file_name is accessible by others. Please run chmod 0600 $creds_file_name" - if stat($creds_file_name)->mode & 07777 != 0600; - - # Read file contents into a string. - open my $creds_fh, '<', $creds_file_name - or die "Unable to read login credentials from $creds_file_name: $!"; - my $creds_file_contents = join '', <$creds_fh>; - close $creds_fh; - - # Parse and return available credentials to be set as object attributes. - my %attrs; - my %parsed_creds = $creds_file_contents =~ /^(\S+)\s*=\s*(\S+)/gm; - $attrs{login_id} = $parsed_creds{username} if defined $parsed_creds{username}; - $attrs{password} = $parsed_creds{password} if defined $parsed_creds{password}; - return \%attrs; + my %args = @_; + if(exists($args{login_id}) && exists($args{password})) + { + my %attrs; + $attrs{login_id} = $args{login_id}; + $attrs{password} = $args{password}; + return \%attrs; + } + else + { + # See if there's a file with login credentials and return if not. + my $creds_file_name = $class->creds_file_name; + return unless -s $creds_file_name; + + # Don't allow it to be readable or writable by others, for security reasons. + die "$creds_file_name is accessible by others. Please run chmod 0600 $creds_file_name" + if stat($creds_file_name)->mode & 07777 != 0600; + + # Read file contents into a string. + open my $creds_fh, '<', $creds_file_name + or die "Unable to read login credentials from $creds_file_name: $!"; + my $creds_file_contents = join '', <$creds_fh>; + close $creds_fh; + + # Parse and return available credentials to be set as object attributes. + my %attrs; + my %parsed_creds = $creds_file_contents =~ /^(\S+)\s*=\s*(\S+)/gm; + $attrs{login_id} = $parsed_creds{username} if defined $parsed_creds{username}; + $attrs{password} = $parsed_creds{password} if defined $parsed_creds{password}; + return \%attrs; + } }
This has been fixed, thanks.