Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
This is the Perl distribution WWW-Yahoo-Smushit. | ||
|
||
Installing WWW-Yahoo-Smushit is straightforward. | ||
|
||
## Installation with cpanm | ||
|
||
If you have cpanm, you only need one line: | ||
|
||
% cpanm WWW::Yahoo::Smushit | ||
|
||
If you are installing into a system-wide directory, you may need to pass the | ||
"-S" flag to cpanm, which uses sudo to install the module: | ||
|
||
% cpanm -S WWW::Yahoo::Smushit | ||
|
||
## Installing with the CPAN shell | ||
|
||
Alternatively, if your CPAN shell is set up, you should just be able to do: | ||
|
||
% cpan WWW::Yahoo::Smushit | ||
|
||
## Manual installation | ||
|
||
As a last resort, you can manually install it. Download the tarball, untar it, | ||
then build it: | ||
|
||
% perl Makefile.PL | ||
% make && make test | ||
|
||
Then install it: | ||
|
||
% make install | ||
|
||
If you are installing into a system-wide directory, you may need to run: | ||
|
||
% sudo make install | ||
|
||
## Documentation | ||
|
||
WWW-Yahoo-Smushit documentation is available as POD. | ||
You can run perldoc from a shell to read the documentation: | ||
|
||
% perldoc WWW::Yahoo::Smushit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
INSTALL | ||
LICENSE | ||
MANIFEST | ||
META.json | ||
META.yml | ||
Makefile.PL | ||
README | ||
dist.ini | ||
lib/WWW/Yahoo/Smushit.pm | ||
t/00-compile.t | ||
t/000-report-versions.t | ||
t/author-critic.t | ||
t/release-distmeta.t | ||
t/release-eol.t | ||
t/release-pod-coverage.t | ||
t/release-pod-syntax.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"abstract" : "Perl interface to Yahoo Smushit image optimizer", | ||
"author" : [ | ||
"Junior Moraes <fvox@cpan.org>" | ||
], | ||
"dynamic_config" : 0, | ||
"generated_by" : "Dist::Zilla version 4.300002, CPAN::Meta::Converter version 2.110930", | ||
"license" : [ | ||
"perl_5" | ||
], | ||
"meta-spec" : { | ||
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", | ||
"version" : "2" | ||
}, | ||
"name" : "WWW-Yahoo-Smushit", | ||
"prereqs" : { | ||
"configure" : { | ||
"requires" : { | ||
"ExtUtils::MakeMaker" : "6.30" | ||
} | ||
} | ||
}, | ||
"release_status" : "stable", | ||
"version" : "0.03" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
abstract: 'Perl interface to Yahoo Smushit image optimizer' | ||
author: | ||
- 'Junior Moraes <fvox@cpan.org>' | ||
build_requires: {} | ||
configure_requires: | ||
ExtUtils::MakeMaker: 6.30 | ||
dynamic_config: 0 | ||
generated_by: 'Dist::Zilla version 4.300002, CPAN::Meta::Converter version 2.110930' | ||
license: perl | ||
meta-spec: | ||
url: http://module-build.sourceforge.net/META-spec-v1.4.html | ||
version: 1.4 | ||
name: WWW-Yahoo-Smushit | ||
version: 0.03 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
use strict; | ||
use warnings; | ||
|
||
|
||
|
||
use ExtUtils::MakeMaker 6.30; | ||
|
||
|
||
|
||
my %WriteMakefileArgs = ( | ||
"ABSTRACT" => "Perl interface to Yahoo Smushit image optimizer", | ||
"AUTHOR" => "Junior Moraes <fvox\@cpan.org>", | ||
"BUILD_REQUIRES" => {}, | ||
"CONFIGURE_REQUIRES" => { | ||
"ExtUtils::MakeMaker" => "6.30" | ||
}, | ||
"DISTNAME" => "WWW-Yahoo-Smushit", | ||
"EXE_FILES" => [], | ||
"LICENSE" => "perl", | ||
"NAME" => "WWW::Yahoo::Smushit", | ||
"PREREQ_PM" => {}, | ||
"VERSION" => "0.03", | ||
"test" => { | ||
"TESTS" => "t/*.t" | ||
} | ||
); | ||
|
||
|
||
unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { | ||
my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; | ||
my $pp = $WriteMakefileArgs{PREREQ_PM}; | ||
for my $mod ( keys %$br ) { | ||
if ( exists $pp->{$mod} ) { | ||
$pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; | ||
} | ||
else { | ||
$pp->{$mod} = $br->{$mod}; | ||
} | ||
} | ||
} | ||
|
||
delete $WriteMakefileArgs{CONFIGURE_REQUIRES} | ||
unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; | ||
|
||
WriteMakefile(%WriteMakefileArgs); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name = WWW-Yahoo-Smushit | ||
version = 0.03 | ||
author = Junior Moraes <fvox@cpan.org> | ||
license = Perl_5 | ||
copyright_holder = Junior Moraes | ||
|
||
[@Basic] | ||
[MetaJSON] | ||
[InstallGuide] | ||
[ReadmeFromPod] | ||
|
||
[ReportVersions] | ||
[CriticTests] | ||
[CompileTests] | ||
[PodSyntaxTests] | ||
[MetaTests] | ||
[EOLTests] | ||
[PodCoverageTests] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package WWW::Yahoo::Smushit; | ||
|
||
use strict; | ||
use warnings; | ||
use Moose; | ||
use LWP::UserAgent; | ||
use JSON; | ||
|
||
our $VERSION = '0.03'; | ||
|
||
has _ua => ( | ||
is => 'rw', | ||
lazy => 1, | ||
required => 1, | ||
default => sub { LWP::UserAgent->new; } | ||
); | ||
|
||
has _service_url => ( | ||
is => 'ro', | ||
isa => 'Str', | ||
default => 'http://www.smushit.com/ysmush.it/ws.php?img=', | ||
required => 1 | ||
); | ||
|
||
sub upload_by_url { | ||
my ($self, $img_url) = @_; | ||
|
||
my $req = $self->_ua->get($self->_service_url . $img_url); | ||
|
||
my $json = JSON->new->allow_nonref; | ||
my $resp = $json->decode($req->content); | ||
return 1 | ||
if($self->_create_attrs_from_json($resp)); | ||
|
||
return 0; | ||
} | ||
|
||
sub _create_attrs_from_json { | ||
my ($self, $json) = @_; | ||
|
||
for (keys %{$json}) { | ||
$self->meta->add_attribute($_, is => 'rw'); | ||
$self->$_($json->{$_}); | ||
} | ||
|
||
$self->meta->make_immutable; | ||
|
||
return 0 | ||
if not keys %{$json} | ||
or defined $json->{error}; | ||
return 1; | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=encoding utf8 | ||
=head1 NAME | ||
WWW::Yahoo::Smushit - Perl interface to Yahoo Smushit image optimizer | ||
=head1 SYNOPSIS | ||
my $st = new WWW::Yahoo::Smushit; | ||
if($st->upload_by_url('http://img3.imageshack.us/img3/562/synyrt2.jpg')) { | ||
printf("Image url:\t%s\nNew image:\t%s\nNew size:\t%s\nOld size:\t%s\nPercent:\t%s%%\n", | ||
$st->src, $st->dest, $st->dest_size, $st->src_size, $st->percent); | ||
} | ||
else { | ||
printf("Oops! Something is wrong...\n\nError:\t%s\n", $st->error); | ||
} | ||
=head1 DESCRIPTION | ||
Smush.it is a service to optimize images, removing some unnecessary data. | ||
=head1 METHODS | ||
=head2 upload_by_url($img_url) | ||
Send a request to the Smushit via http and retrieves the JSON object. | ||
=head1 INTERNALS | ||
=head2 _create_attrs_from_json | ||
Get the JSON and create the attributes. | ||
=head2 SEE ALSO | ||
L<Smushit|http://smush.it/>. | ||
=head1 AUTHOR | ||
Junior Moraes <fvox@cpan.org> | ||
=head1 COPYRIGHT AND LICENSE | ||
Copyright (C) 2011 by Junior Moraes | ||
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
|
||
|
||
use File::Find; | ||
use File::Temp qw{ tempdir }; | ||
|
||
my @modules; | ||
find( | ||
sub { | ||
return if $File::Find::name !~ /\.pm\z/; | ||
my $found = $File::Find::name; | ||
$found =~ s{^lib/}{}; | ||
$found =~ s{[/\\]}{::}g; | ||
$found =~ s/\.pm$//; | ||
# nothing to skip | ||
push @modules, $found; | ||
}, | ||
'lib', | ||
); | ||
|
||
my @scripts; | ||
if ( -d 'bin' ) { | ||
find( | ||
sub { | ||
return unless -f; | ||
my $found = $File::Find::name; | ||
# nothing to skip | ||
open my $FH, '<', $_ or do { | ||
note( "Unable to open $found in ( $! ), skipping" ); | ||
return; | ||
}; | ||
my $shebang = <$FH>; | ||
return unless $shebang =~ /^#!.*?\bperl\b\s*$/; | ||
push @scripts, $found; | ||
}, | ||
'bin', | ||
); | ||
} | ||
|
||
my $plan = scalar(@modules) + scalar(@scripts); | ||
$plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); | ||
|
||
{ | ||
# fake home for cpan-testers | ||
# no fake requested ## local $ENV{HOME} = tempdir( CLEANUP => 1 ); | ||
|
||
like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) | ||
for sort @modules; | ||
|
||
SKIP: { | ||
eval "use Test::Script 1.05; 1;"; | ||
skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; | ||
foreach my $file ( @scripts ) { | ||
my $script = $file; | ||
$script =~ s!.*/!!; | ||
script_compiles( $file, "$script script compiles" ); | ||
} | ||
} | ||
} |
Oops, something went wrong.