Hi monks!

A few days ago, I thought of a module that would enable to put some images easily on the internet. Luckily, there is a website that allows people to put their pictures on, freely ("free" as in "be offered a beer").
Taking my courage with both hands I wrote my first module ever, an OO module, above all \o/
It lets you put a picture on ImagesHack.us, and gives you all the links to the image, ie direct links, forum links, and all that stuff the website gives you pre-chewed.
The code is still a little bit dirty, some vars have a one letter-long name, but when I clean it, if I see you like this module, I'll put it on CPAN, probably under WWW:: (unless you have a better idea, but I don't think it deserves ACME::)


Anyway...All comments welcome...

The module itself
#!/usr/bin/perl -w #===================================================================== +========== # # FILE: ImagesHack.pm # # USAGE: use WWW::ImagesHack # # DEshowImageCRIPTION: upload a file on imageshack.us # # OPTIONshowImage: --- # REQUIREMENTshowImage: --- # BUGshowImage: --- # NOTEshowImage: --- # AUTHOR: Axioplase (Axioplase), <dev@pied.mine.nu> # COMPANY: None # VERshowImageION: 1.0 # CREATED: 15.09.2005 01:25:46 CEshowImageT # REVIshowImageION: --- #===================================================================== +========== package WWW::ImagesHack; use base 'Exporter'; use strict; #for those who dare use LWP::UserAgent; use HTML::Form; use HTML::TokeParser; sub new { my $class = shift; # $_[0] contains the class name my $img = shift; # $_[1] contains the name of the file my %liste; my $self = {}; bless( $self, $class ); $self->{image} = $img; return $self; } sub upload { my $self=shift; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => 'http://imageshack.us/'); $req->content_type('application/x-www-form-urlencoded'); my $res = $ua->request($req); my $form = (HTML::Form->parse($res))[0]; $form->value( 'fileupload',$self->{image} ); my $ares= ${$ua->request($form->click)}{_content}; my $p = HTML::TokeParser->new(\$ares); foreach(qw /thumbnailForWebsite thumbnailForForums1 thumbnailForForu +ms2 hotlinkForForums1 hotlinkForForums2 hotlinkForWebsite showImage d +irectLinkToImage/){ my $token = $p->get_tag("input"); $self->{liste}{$_} = $token->[1]{value}; } } sub get_all { my $self = shift; return $self->{liste}; } sub get_thumbnailForWebsite{ my $self = shift; return $self->{liste}{thumbnailForWebsite}; } sub get_thumbnailForForums1{ my $self = shift; return $self->{liste}{thumbnailForForums1}; } sub get_thumbnailForForums2{ my $self = shift; return $self->{liste}{thumbnailForForums2}; } sub get_hotlinkForForums1{ my $self = shift; return $self->{liste}{hotlinkForForums1}; } sub get_hotlinkForForums2{ my $self = shift; return $self->{liste}{hotlinkForForums2}; } sub get_hotlinkForWebsite{ my $self = shift; return $self->{liste}{hotlinkForWebsite}; } sub get_showImage{ my $self = shift; return $self->{liste}{showImage}; } sub get_directLinkToImage{ my $self = shift; return $self->{liste}{directLinkToImage}; } 1;



And the test

#!/usr/bin/perl -w #===================================================================== +========== # # FILE: testimageshack.pl # # USAGE: ./testimageshack.pl # # DESCRIPTION: a test file for ImagesHack.pm # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Axioplase (Axioplase), <dev@pied.mine.nu> # COMPANY: None # VERSION: 1.0 # CREATED: 15.09.2005 03:08:31 CEST # REVISION: --- #===================================================================== +========== use strict; use lib '/home/Pied/Code/Perl/WWW::ImagesHack/'; use WWW::ImagesHack; my $img='/tmp/foo.jpg'; #edit this.... my $ih=WWW::ImagesHack->new($img); $ih->upload; my %res=%{$ih->get_all}; foreach (keys %res){ print "$_ => $res{$_}\n"; } print "\n\n"; print $ih->get_thumbnailForWebsite,"\n"; print $ih->get_thumbnailForForums1,"\n"; print $ih->get_thumbnailForForums2,"\n"; print $ih->get_hotlinkForForums1,"\n"; print $ih->get_hotlinkForForums2,"\n"; print $ih->get_hotlinkForWebsite,"\n"; print $ih->get_showImage,"\n"; print $ih->get_directLinkToImage,"\n";




P!

Are the monkeys gone yet?

In reply to WWW::ImagesHack by Pied

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.