App-Kit

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

t/00.notry.t
t/00.rw_env.t
t/00.rw_pm.t
t/00.xtend.t
t/00.z-cpanel.t
t/00.z-pangea.t
t/01.detect.t
t/02.ctype.t
t/03.str.t
t/04.ns.t
t/05.locale.t
t/06.http.t
t/07.fs.t
t/07.fs-psgi.t
t/08.log.t
t/09.db-2.t
t/09.db.t
t/10.ex-2.t
t/10.ex.t
t/lib/MyTest.pm
t/perlcritic.t

lib/App/Kit.pm  view on Meta::CPAN

=head2 only what you need, when you need it

Only load and instantiate the things your code actually does, with no effort.

Reuse them throughout the code base, again, with no effort!

=head2 use default objects or set your own

The defaults will work and as your project expands you can customize if needed without needing to refactor your code. 

For example, once you sprint the localization setup, you can change your class’s locale() to use your object.

=head2 easy mocking (for your tests!)

By default the lazy façade methods are readonly (technically 'rwp' so the class can fiddle with them internally if it needs to).

You can change make them readwrite via either of 2 mechanisms before the class is built via use().

Either:

    use App::Kit::Util::RW; # must be loaded before App::Kit is use()d

lib/App/Kit.pm  view on Meta::CPAN

See L<Role::Multiton> for more details.

=head2 Lazy façade methods

Each method returns a lazy loaded/instantiated object that implements the actual functionality.

=head3 $app->log

Lazy façade to a logging object via L<App::Kit::Role::Log>.

=head3 $app->locale

Lazy façade to a maketext() object via L<App::Kit::Role::Locale>. 

Has all the methods any L<Locale::Maketext::Utils> based object would have.

Localize your code now without needing an entire subsystem in place just yet!

=head3 $app->detect

Lazy façade to a context detection object via L<App::Kit::Role::Detect>.

lib/App/Kit/Obj/DB.pm  view on Meta::CPAN

        my ( $self, @connect ) = @_;

        my $dbh = DBI->connect(@connect) || die "Could not connect to database: " . DBI->errstr();

        # TODO: similar thing for other drivers ?
        if ( $dbh->{Driver}{Name} eq 'mysql' ) {
            $dbh->do('SET CHARACTER SET utf8') or die $dbh->errstr;
            $dbh->do("SET NAMES 'utf8'")       or die $dbh->errstr;

            # This will make sure TZ offsets don't goof your datetime queries.
            #     Human readable results will of course need adjusted (and formatted) (hint: locale->datetime(…))
            #         which they would anyway, this just makes it easier to know you are in a universally sane state:
            # Add UTC via: mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root mysql -p
            $dbh->do(q{SET time_zone = 'UTC'});    # or die $dbh->errstr;
        }
        elsif ( $dbh->{Driver}{Name} eq 'SQLite' ) {
            $dbh->do('PRAGMA encoding = "UTF-8"');    # probably too late, default anyway. so at worst a no-op; at best we get utf-8
        }

        return $dbh;
    };

lib/App/Kit/Role/Locale.pm  view on Meta::CPAN

package App::Kit::Role::Locale;

## no critic (RequireUseStrict) - Moo::Role does strict/warnings
use Moo::Role;

our $VERSION = '0.1';

has locale => (
    is => ( $INC{'App/Kit/Util/RW.pm'} || $ENV{'App-Kit-Util-RW'} ? 'rw' : 'rwp' ),
    lazy    => 1,
    default => sub {
        require Locale::Maketext::Utils::Mock;    # Perl::DependList-IS_DEP(Locale::Maketext::Utils)
        return Locale::Maketext::Utils::Mock->get_handle();
    },
);

1;

lib/App/Kit/Role/Locale.pm  view on Meta::CPAN

This document describes App::Kit::Role::Locale version 0.1

=head1 SYNOPSIS

In your class:

   with 'App::Kit::Role::Locale';

Then later in your program:

    $app->locale->maketext('Hello World')

=head1 DESCRIPTION

Add lazy façade localization support to your class.

=head1 INTERFACE

This role adds one lazy façade method:

=head2 locale()

Returns a L<Locale::Maketext::Utils::Mock> object for reuse after lazy loading the module.

=head1 DIAGNOSTICS

Throws no warnings or errors of its own.

=head1 CONFIGURATION AND ENVIRONMENT

Requires no configuration files or environment variables.

lib/App/Kit/cPanel.pm  view on Meta::CPAN


has '+log' => (
    is => ( $INC{'App/Kit/Util/RW.pm'} || $ENV{'App-Kit-Util-RW'} ? 'rw' : 'rwp' ),
    lazy    => 1,
    default => sub {
        require Cpanel::Logger;
        return Cpanel::Logger->new();
    },
);

has '+locale' => (
    is => ( $INC{'App/Kit/Util/RW.pm'} || $ENV{'App-Kit-Util-RW'} ? 'rw' : 'rwp' ),
    lazy    => 1,
    default => sub {
        require Cpanel::Locale;
        return Cpanel::Locale->get_handle();
    },
);

1;

__END__

=encoding utf-8

=head1 App::Kit for cPanel servers. 

Uses cPanel’s logger and locale systems for log() and locale() respectively.

See L<App::Kit> for details.

t/00.xtend.t  view on Meta::CPAN


can_ok( $app, 'foo' );
is( $app->foo, 42, 'new attr works' );

can_ok( $app, 'bar' );
is( $app->bar, 23, 'new method works' );

can_ok( $app, 'log' );
is( $app->log, 'busted log', 'overridden attr works' );

can_ok( $app, 'locale' );
isa_ok( $app->locale, 'Locale::Maketext::Utils::Mock::en', 'non-overridden attr works' );

my $m = MyTest->multiton();
isa_ok( $m, 'MyTest' );
isa_ok( $m, 'App::Kit' );
is( $m, MyTest->multiton, 'multiton() w/ no args is same' );
is( MyTest->multiton( a => 1 ), MyTest->multiton( { a => 1 } ), 'multiton() w/ list and ref are same' );
isnt( $m, MyTest->multiton( { a => 1 } ), 'multiton() w/ diff args are diff' );

package zong;

t/00.z-cpanel.t  view on Meta::CPAN


my $app = App::Kit::cPanel->instance;

isa_ok( $app, 'App::Kit::cPanel' );
isa_ok( $app, 'App::Kit' );

SKIP: {
    eval 'require Cpanel;';
    skip "cPanel module tests can only run on cPanel servers", 2 if $@;
    isa_ok( $app->log,    'Cpanel::Logger' );
    isa_ok( $app->locale, 'Cpanel::Locale' );
}

done_testing;

t/05.locale.t  view on Meta::CPAN

use Test::More;

use App::Kit;

diag("Testing locale() for App::Kit $App::Kit::VERSION");

my $app = App::Kit->new();

ok( !exists $INC{'Locale/Maketext/Utils/Mock.pm'}, 'lazy under pinning not loaded before' );
isa_ok( $app->locale, 'Locale::Maketext::Utils::Mock::en' );
ok( exists $INC{'Locale/Maketext/Utils/Mock.pm'}, 'lazy under pinning loaded after' );

is( $app->locale->maketext( 'Hello World: [_1]', 42 ), 'Hello World: 42', 'locale can maketext' );

done_testing;



( run in 1.950 second using v1.01-cache-2.11-cpan-ceb78f64989 )