From 964a6a1404beddd3abb31e2442cb2dc68bba8dc2 Mon Sep 17 00:00:00 2001 From: Magnus Woldrich Date: Tue, 29 Jan 2019 12:02:55 +0100 Subject: [PATCH] initial --- MANIFEST | 18 +++++ Makefile.PL | 58 ++++++++++++++++ README | 60 +++++++++++++++++ examples/dzen_load.pl | 40 +++++++++++ examples/fgonbg | 11 +++ lib/Term/ExtendedColor/Dzen.pm | 119 +++++++++++++++++++++++++++++++++ t/00-load.t | 9 +++ t/01-pod.t | 12 ++++ t/10-strict.t | 20 ++++++ t/20-synopsis.t | 14 ++++ t/30-eol.t | 15 +++++ t/30-fixme.t | 20 ++++++ t/30-notabs.t | 16 +++++ t/40-kwalitee.t | 29 ++++++++ t/50-complexity.t | 45 +++++++++++++ t/60-pod-coverage.t | 22 ++++++ t/60-pod-syntax.t | 16 +++++ t/80-minperl.t | 15 +++++ 18 files changed, 539 insertions(+) create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 examples/dzen_load.pl create mode 100644 examples/fgonbg create mode 100755 lib/Term/ExtendedColor/Dzen.pm create mode 100644 t/00-load.t create mode 100644 t/01-pod.t create mode 100644 t/10-strict.t create mode 100644 t/20-synopsis.t create mode 100644 t/30-eol.t create mode 100644 t/30-fixme.t create mode 100644 t/30-notabs.t create mode 100644 t/40-kwalitee.t create mode 100644 t/50-complexity.t create mode 100644 t/60-pod-coverage.t create mode 100644 t/60-pod-syntax.t create mode 100644 t/80-minperl.t diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..4032f4c --- /dev/null +++ b/MANIFEST @@ -0,0 +1,18 @@ +lib/Term/ExtendedColor/Dzen.pm +Makefile.PL +MANIFEST +t/00-load.t +t/01-pod.t +t/10-strict.t +t/20-synopsis.t +t/30-eol.t +t/30-fixme.t +t/30-notabs.t +t/40-kwalitee.t +t/50-complexity.t +t/60-pod-coverage.t +t/60-pod-syntax.t +t/80-minperl.t +README +examples/dzen_load.pl +examples/fgonbg diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..83af61f --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,58 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile1( + META_MERGE => { + resources => { + repository => q{https://github.com/trapd00r/Term-ExtendedColor-Dzen}, + bugtracker => q{https://github.com/trapd00r/Term-ExtendedColor-Dzen/issues}, + }, + }, + + NAME => q{Term::ExtendedColor::Dzen}, + AUTHOR => q{Magnus Woldrich }, + ABSTRACT => q{Color input and add dzen compatible attributes}, + VERSION_FROM => q{lib/Term/ExtendedColor/Dzen.pm}, + LICENSE => q{perl}, +# EXE_FILES => [ glob('bin/*') ], + PREREQ_PM => { }, + MIN_PERL_VERSION => 5.010, + MAN1PODS => { }, + dist => { COMPRESS => q{gzip -9f}, SUFFIX => q{gz}, }, + clean => { FILES => q{Term-ExtendedColor-Dzen-*}, }, +); + +sub WriteMakefile1 { + my %params = @_; + my $eumm_version = $ExtUtils::MakeMaker::VERSION; + $eumm_version = eval $eumm_version; + die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; + die "License not specified" if not exists $params{LICENSE}; + if ($params{AUTHOR} and ref($params{AUTHOR}) eq q{ARRAY} + and $eumm_version < 6.5705) { + $params{META_ADD}->{author}=$params{AUTHOR}; + $params{AUTHOR}=join(', ',@{$params{AUTHOR}}); + } + if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { + #EUMM 6.5502 has problems with BUILD_REQUIRES + $params{PREREQ_PM}={ + %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} + }; + delete $params{BUILD_REQUIRES}; + } + delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; + delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; + delete $params{META_MERGE} if $eumm_version < 6.46; + delete $params{META_ADD} if $eumm_version < 6.46; + delete $params{LICENSE} if $eumm_version < 6.31; + delete $params{AUTHOR} if $] < 5.005; + delete $params{ABSTRACT_FROM} if $] < 5.005; + delete $params{BINARY_LOCATION} if $] < 5.005; + + #delete $params{MAN3PODS}->{'README.pod'}; + + WriteMakefile(%params); +} + + diff --git a/README b/README new file mode 100644 index 0000000..4f92461 --- /dev/null +++ b/README @@ -0,0 +1,60 @@ +NAME + Term::ExtendedColor::Dzen - Color input and add dzen(2) compatible + attributes + +SYNOPSIS + use Term::ExtendedColor::Dzen qw(fgd bgd); + + print fgd('#ff0000', 'this is red foreground'); + print bgd('#fff00', 'this is yellow background'); + + print fgd('#000', bgd('#ffffff', 'this is black on white background')); + +DESCRIPTION + Term::ExtendedColor::Dzen provides functionality for coloring input data + with dzen compatible attributes. + +EXPORTS + None by default. + +FUNCTIONS + fgd('#fff', $string) + Sets foreground color. When called without arguments, returns the fg + reset string. + + my $white_fg = fgd('#fff', 'white foreground'); + + bgd('#000', $string) + Sets background color. When called without arguments, returns the bg + reset string. + + my $black_bg = bg('#000', 'black background'); + + Like "fgd()", but sets background colors. + + These two can be combined: + + my $str = fgd('#000', bgd('#ffffff', 'this is black on white background')); + + which yields the combined string: + + ^fg(#000)^bg(#fff)this is black on white background^bg()^fg() + +SEE ALSO + dzen + + dzen2 + +AUTHOR + Magnus Woldrich + CPAN ID: WOLDRICH + m@japh.se + http://japh.se + + Copyright 2019- the Term::ExtendedColor::Dzen "AUTHOR" and + "CONTRIBUTORS" as listed above. + +LICENSE + This library is free software; you may redistribute it and/or modify it + under the same terms as Perl itself. + diff --git a/examples/dzen_load.pl b/examples/dzen_load.pl new file mode 100644 index 0000000..0d48c93 --- /dev/null +++ b/examples/dzen_load.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# vim: ft=perl:fdm=marker:fmr=#<,#>:fen:et:sw=2: +use strict; +use vars qw($VERSION); +use autodie qw(:all); + +my $APP = 'dzen-uptime'; +$VERSION = '0.001'; + +# $ while true; do perl dzen_uptime.pl; sleep 1; done | dzen2 + +use Number::RGB; +use Term::ExtendedColor::Dzen qw(fgd bgd); + + +open(my $fh, '<', '/proc/loadavg') or die $!; +chomp(my $uptime = <$fh>); +close $fh; + +my @avg = $uptime =~ m/(\d+[.]\d+)/g; + +$avg[0] = fgd(Number::RGB->new(rgb => randhex())->hex, $avg[0]); +$avg[1] = fgd(Number::RGB->new(rgb => randhex())->hex, $avg[1]); +$avg[2] = fgd(Number::RGB->new(rgb => randhex())->hex, $avg[2]); + +my $bg = Number::RGB->new(rgb => randhex())->hex; + +$avg[0] = bgd($bg, $avg[0]); +$avg[1] = bgd($bg, $avg[1]); +$avg[2] = bgd($bg, $avg[2]); + +print join('', @avg), "\n"; + +sub randhex { + return [ + int(rand(255)), + int(rand(255)), + int(rand(255)), + ] +} diff --git a/examples/fgonbg b/examples/fgonbg new file mode 100644 index 0000000..1bb0b29 --- /dev/null +++ b/examples/fgonbg @@ -0,0 +1,11 @@ +#!/usr/bin/perl +# vim: ft=perl:fdm=marker:fmr=#<,#>:fen:et:sw=2: +use strict; +use vars qw($VERSION); +use autodie qw(:all); + +use Term::ExtendedColor::Dzen qw(fgd bgd); + +use feature 'say'; + +say fgd('#000', bgd('#fff', 'this is black on white background')); diff --git a/lib/Term/ExtendedColor/Dzen.pm b/lib/Term/ExtendedColor/Dzen.pm new file mode 100755 index 0000000..da8d5df --- /dev/null +++ b/lib/Term/ExtendedColor/Dzen.pm @@ -0,0 +1,119 @@ +package Term::ExtendedColor::Dzen; +use strict; +use warnings; + +BEGIN { + use Exporter; + use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); + + $VERSION = '0.001'; + @ISA = qw(Exporter); + + @EXPORT_OK = qw( + fgd + bgd + ); + + %EXPORT_TAGS = ( + attributes => [ qw(fgd bgd) ], + all => [ @EXPORT_OK ], + ); +} + + +sub fgd { + if(!@_) { + return "^fg()" + } + my ($color, $data) = @_; + return "^fg($color)$data^fg()"; +} + +sub bgd { + if(!@_) { + return "^bg()" + } + my ($color, $data) = @_; + return "^bg($color)$data^bg()"; +} + + + + +1; + +__END__ + +=pod + +=head1 NAME + +Term::ExtendedColor::Dzen - Color input and add dzen(2) compatible attributes + +=head1 SYNOPSIS + + use Term::ExtendedColor::Dzen qw(fgd bgd); + + print fgd('#ff0000', 'this is red foreground'); + print bgd('#fff00', 'this is yellow background'); + + print fgd('#000', bgd('#ffffff', 'this is black on white background')); + +=head1 DESCRIPTION + +B provides functionality for coloring input data +with dzen compatible attributes. + +=head1 EXPORTS + +None by default. + +=head1 FUNCTIONS + +=head2 fgd('#fff', $string) + +Sets foreground color. When called without arguments, returns the fg +reset string. + + my $white_fg = fgd('#fff', 'white foreground'); + +=head2 bgd('#000', $string) + +Sets background color. When called without arguments, returns the bg +reset string. + + my $black_bg = bg('#000', 'black background'); + +Like C, but sets background colors. + +These two can be combined: + + my $str = fgd('#000', bgd('#ffffff', 'this is black on white background')); + +which yields the combined string: + + ^fg(#000)^bg(#fff)this is black on white background^bg()^fg() + + +=head1 SEE ALSO + +L + +L + +=head1 AUTHOR + + Magnus Woldrich + CPAN ID: WOLDRICH + m@japh.se + http://japh.se + +Copyright 2019- the B L +and L as listed above. + +=head1 LICENSE + +This library is free software; you may redistribute it and/or modify it under +the same terms as Perl itself. + +=cut diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..36fc842 --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,9 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More tests => 1; + +BEGIN { + use_ok('Term::ExtendedColor::Dzen'); +} + diff --git a/t/01-pod.t b/t/01-pod.t new file mode 100644 index 0000000..0606426 --- /dev/null +++ b/t/01-pod.t @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval "use Test::Pod 1.00"; ## no critic +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +all_pod_files_ok( all_pod_files( qw(blib) ) ); diff --git a/t/10-strict.t b/t/10-strict.t new file mode 100644 index 0000000..68506a8 --- /dev/null +++ b/t/10-strict.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl +# test for syntax, strict and warnings + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval 'use Test::Strict'; ## no critic +plan skip_all => 'Test::Strict required' if $@; + +{ + no warnings 'once'; + $Test::Strict::TEST_WARNINGS = 0; +} + +all_perl_files_ok(qw/ lib t /); diff --git a/t/20-synopsis.t b/t/20-synopsis.t new file mode 100644 index 0000000..4c6c57d --- /dev/null +++ b/t/20-synopsis.t @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More; + +eval "use Test::Synopsis"; ## no critic + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +plan skip_all => 'Test::Synopsis required for testing synopsis' if $@; + +all_synopsis_ok() diff --git a/t/30-eol.t b/t/30-eol.t new file mode 100644 index 0000000..164c62b --- /dev/null +++ b/t/30-eol.t @@ -0,0 +1,15 @@ +#!/usr/bin/perl +# test for correct line endings + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval 'use Test::EOL'; ## no critic +plan skip_all => 'Test::EOL required' if $@; + +all_perl_files_ok( { trailing_whitespace => 1 }, qw/ lib t / ); diff --git a/t/30-fixme.t b/t/30-fixme.t new file mode 100644 index 0000000..907a624 --- /dev/null +++ b/t/30-fixme.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl +# test code for FIXME/BUG/TODO/XXX/NOTE labels + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval 'use Test::Fixme'; ## no critic +plan skip_all => 'Test::Fixme required' if $@; + +run_tests( + match => qr/FIXME|BUG\b|XXX/, + filename_match => qr/\.(pm)$/, + where => [ qw( lib ) ] +); + diff --git a/t/30-notabs.t b/t/30-notabs.t new file mode 100644 index 0000000..b10ecdc --- /dev/null +++ b/t/30-notabs.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl +# test for presence of tabs in sources + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval 'use Test::NoTabs'; ## no critic +plan skip_all => 'Test::NoTabs required' if $@; + +all_perl_files_ok(qw/ lib t /); + diff --git a/t/40-kwalitee.t b/t/40-kwalitee.t new file mode 100644 index 0000000..693fb83 --- /dev/null +++ b/t/40-kwalitee.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl +# test the kwalitee of a distribution + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval { + require Test::Kwalitee; + Test::Kwalitee->import( + tests => [ + qw( + -has_test_pod + -has_test_pod_coverage + -has_readme + -has_manifest + -has_changelog + -has_meta_yml + ) + ] + ); +}; + +plan( skip_all => 'Test::Kwalitee not installed; skipping' ) if $@; + diff --git a/t/50-complexity.t b/t/50-complexity.t new file mode 100644 index 0000000..dfdbfd8 --- /dev/null +++ b/t/50-complexity.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl +# test sources by Perl Code Metrics System + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +{ + ## no critic + eval ' + use Perl::Metrics::Simple; + use File::Find::Rule (); + use File::Find::Rule::Perl (); + '; +} +plan skip_all => 'Perl::Metrics::Simple, File::Find::Rule and File::Find::Rule::Perl required' if $@; + +# configure this to match your needs +my $max_complexity = 40; +my $max_lines = 80; + +my @files = File::Find::Rule->perl_file->in(qw/ lib t /); +my $analzyer = Perl::Metrics::Simple->new; +my @subs; + +foreach (@files) { + my $analysis = $analzyer->analyze_files($_); + push( @subs, $_ ) foreach ( @{ $analysis->subs } ); +} + +plan tests => ( scalar @subs ) * 2; + +foreach my $sub (@subs) { + my $name = $sub->{name} . ' in ' . $sub->{path}; + my $complexity = $sub->{mccabe_complexity}; + my $lines = $sub->{lines}; + + ok( $complexity <= $max_complexity, "Cyclomatic comlexity for $name is too big ($complexity > $max_complexity)" ); + ok( $lines <= $max_lines, "Lines count for $name is too big ($lines > $max_lines)" ); +} + diff --git a/t/60-pod-coverage.t b/t/60-pod-coverage.t new file mode 100644 index 0000000..f3b5d3b --- /dev/null +++ b/t/60-pod-coverage.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl +# test sources for pod coverage + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +{ + ## no critic + eval ' + use Test::Pod::Coverage 1.08; + use Pod::Coverage 0.18; + '; +} +plan skip_all => 'Test::Pod::Coverage (>=1.08) and Pod::Coverage (>=0.18) are required' if $@; + +all_pod_coverage_ok(qw/ lib t /); + diff --git a/t/60-pod-syntax.t b/t/60-pod-syntax.t new file mode 100644 index 0000000..2d403aa --- /dev/null +++ b/t/60-pod-syntax.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl +# test sources for POD syntax + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval 'use Test::Pod 1.22'; ## no critic +plan skip_all => 'Test::Pod (>=1.22) is required' if $@; + +all_pod_files_ok(qw/ lib t /); + diff --git a/t/80-minperl.t b/t/80-minperl.t new file mode 100644 index 0000000..d6dfbfd --- /dev/null +++ b/t/80-minperl.t @@ -0,0 +1,15 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +unless(exists($ENV{RELEASE_TESTING})) { + plan skip_all => 'these tests are for release candidate testing'; +} + +eval 'use Test::MinimumVersion'; ## no critic + +plan skip_all => 'Test::MinimumVersion required' if $@; + +all_minimum_version_ok('5.010');