CollegeHumor: Fix video URLs, and the title is in the XML now!
[videosite.git] / videosite / Base.pm
index 5d796d8..55a15e6 100644 (file)
@@ -4,12 +4,14 @@
 package videosite::Base;
 
 use strict;
+use LWP::UserAgent;
+use HTTP::Cookies;
 use Data::Dumper;
 
 sub new {
     my $class = shift;
-    my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}};
-
+    my $self = {'_DEBUG' => 0, '_OUT' => sub {printf(@_)}};
+    
     bless($self, $class);
 
     $self->_prepare_parameters();
@@ -19,11 +21,11 @@ sub new {
 
 sub error {
     my $self = shift;
-    my $t;
+    my @data = @_;
 
-    $t = sprintf(shift(@_), @_);
-    $t =~ s/%/%%/g;
-    $self->{'_OUT'}($t);
+    $data[0] = "(" . ref($self) . ") " . $data[0];
+
+    $self->{'_OUT'}(@data);
 }
 
 sub debug {
@@ -170,4 +172,10 @@ sub setdebug {
     $self->{'_DEBUG'} = shift;
 }
 
+sub ua {
+    my $self = shift;
+
+    return LWP::UserAgent->new('agent' => 'Mozilla/5.0', 'cookie_jar' => HTTP::Cookies->new);
+}
+
 1;