Subject: | stars option for imdb::film.pm |
Date: | Thu, 15 Mar 2012 03:19:29 +0100 |
To: | bug-IMDB-Film [...] rt.cpan.org |
From: | Christian Schneider <anotherschneider [...] googlemail.com> |
Hi Stepanov,
how about a "stars" option inside Film.pm?
As I was interested in the main actors of the movie I got the following
code working like a charm, based on the directors sub. Maybe you want to
include it in some future version?
Keep up the good work!
Christian
=item stars()
Retrieve film stars list each element of which is hash reference -
{ id => <ID>, name => <Name> }:
my @stars = @{ $film->stars() };
=cut
sub stars {
my CLASS_NAME $self = shift;
my $forced = shift || 0;
if($forced) {
my ($parser) = $self->_parser(FORCED);
my (@stars, $tag);
while($tag = $parser->get_tag(MAIN_TAG)) {
my $text = $parser->get_text;
last if $text =~ /stars/i;
}
while ($tag = $parser->get_tag() ) {
my $text = $parser->get_text();
last if $tag->[0] eq '/div';
if($tag->[0] eq 'a' && $tag->[1]{href} && $text !~
/(img|more)/i) {
my($id) = $tag->[1]{href} =~ /(\d+)/;
push @stars, {id => $id, name => $text};
}
}
$self->{_stars} = \@stars;
}
return $self->{_stars};
}