Badger - Perl Application Programming Toolkit


Badger documentation Contained in the Badger distribution.

Index


Code Index:

NAME

Top

Badger - Perl Application Programming Toolkit

SYNOPSIS

Top

    use Badger
        lib        => '../lib',     # like 'use lib' but relative to $Bin
        Filesystem => 'File Dir',   # import from Badger::Filesystem

    use Badger 
        Filesystem => 'Dir File',
        Utils      => 'numlike textlike',
        Constants  => 'ARRAY HASH',
        Codecs     => [codec => 'base64'];

This is equivalent to:

    use Badger;
    use Badger::Filesystem 'Dir File';
    use Badger::Utils      'numlike textlike',
    use Badger::Constants  'ARRAY HASH',
    use Badger::Codecs      codec => 'base64';

DESCRIPTION

Top

The Badger toolkit is a collection of Perl modules designed to simplify the process of building object-oriented Perl applications. It provides a set of foundation classes upon which you can quickly build robust and reliable systems that are simple, sexy and scalable. See Badger::Intro for further information.

The Badger module is a front-end to other Badger modules. You can use it to import any of the exportable items from any other Badger module. Simply specify the module name, minus the Badger:: prefix as a load option.

For example:

    use Badger 
        Filesystem => 'Dir File',
        Utils      => 'numlike textlike',
        Constants  => 'ARRAY HASH',
        Codecs     => [codec => 'base64'];

This is equivalent to:

    use Badger;
    use Badger::Filesystem 'Dir File';
    use Badger::Utils      'numlike textlike',
    use Badger::Constants  'ARRAY HASH',
    use Badger::Codecs      codec => 'base64';

Note that multiple arguments for a module should be defined as a list reference.

    use Badger 
        ...etc...
        Codecs => [codec => 'base64'];

This is equivalent to:

    use Badger::Codecs [codec => 'base64'];

Which is also equivalent to:

    use Badger::Codecs codec => 'base64';

EXPORT HOOKS

Top

The Badger module can import items from any other Badger::* module, as shown in the examples above. The following export hook is also provided.

lib

This performs the same task as use lib in adding a directory to your @INC module include path. However, there are two differences. First, you can specify a directory relative to the directory in which the script exists.

    use Badger lib => '../perl/lib';

For example, consider a directory layout like this:

    my_project/
        bin/
            example_script.pl
        perl/
            lib/
                My/
                    Module.pm
            t/
                my_module.t

The my_project/example_script.pl can be written like so:

    #!/usr/bin/perl

    use Badger lib => '../perl/lib';
    use My::Module;

    # your code here...

This adds my_project/perl/lib to the include path so that the My::Module module can be correctly located. It is equivalent to the following code using the FindBin module.

    #!/usr/bin/perl

    use FindBin '$Bin';
    use lib "$Bin/../perl/lib";
    use My::Module;

METHODS

Top

hub()

Returns a Badger::Hub object.

codec()

Delegates to the Badger::Hub codec() method to return a Badger::Codec object.

    my $base64  = Badger->codec('base64');
    my $encoded = $base64->encode($uncoded);
    my $decoded = $base64->decode($encoded);

config()

Delegates to the Badger::Hub codec() method to return a Badger::Config object. This is still experimental.

TODO

Top

Other methods like codec() to access different Badger modules. These should be generated dynamically on demand.

AUTHOR

Top

Andy Wardley http://wardley.org/

COPYRIGHT

Top

SEE ALSO

Top

http://badgerpower.com/


Badger documentation Contained in the Badger distribution.

package Badger;

use 5.008;
use Carp;
use lib;
use Badger::Hub;
use Badger::Class
    debug      => 0,
    version    => '0.06',
    base       => 'Badger::Base',
    import     => 'class',
    words      => 'HUB',
    constants  => 'PKG ARRAY DELIMITER',
    filesystem => 'Bin',
    exports    => {
        hooks  => {
            lib => [ sub { $_[0]->lib($_[3]) }, 1],
        },
        fail   => \&_export_handler,
    };

our $VERSION = '0.06';              # Just for ExtUtils::MakeMaker.  Ick
our $HUB     = 'Badger::Hub';
our $AUTOLOAD;

sub _export_handler {
    # TODO: we should be able to refactor this down, now that Badger::Exporter
    # can handle this argument shifting
    my ($class, $target, $key, $symbols) = @_;
    croak "You didn't specify a value for the '$key' load option."
        unless @$symbols;
    my $module = join(PKG, $class, $key);
    my $option = shift @$symbols;
    class($module)->load;
    $module->export($target, $option);
    return 1;
}


sub init {
    my ($self, $config) = @_;
    my $hub = $config->{ hub } || $self->class->any_var(HUB);
    unless (ref $hub) {
        class($hub)->load;
        $hub = $hub->new($config);
    }
    $self->{ hub } = $hub;
    return $self;
}

sub lib {
    my ($self, $lib) = @_;
    $lib = [split(DELIMITER, $lib)]
        unless ref $lib eq ARRAY;
    foreach (@$lib) {
        # resolve directories relative to current working directory so that
        # relative paths Just Work[tm], e.g. ../perl/lib as well as absolute
        # paths. e.g. /full/path/to/perl/lib
        my $dir = Bin->dir($_)->must_exist;
        $self->debug("adding lib: $dir") if DEBUG;
        lib->import($dir->absolute);
    }
}

sub hub {
    my $self = shift;

    if (ref $self) {
        return @_
            ? ($self->{ hub } = shift)
            :  $self->{ hub };
    }
    else {
        return @_
            ? $self->class->var(HUB => shift)
            : $self->class->var(HUB)
    }
}

sub codec {
    shift->hub->codec(@_);
}


sub config {
    my $self = shift;
    return $self->hub->config;
}

# TODO: AUTOLOAD method which polls hub to see what it supports

1;

__END__

# Local Variables:
# mode: perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# vim: expandtab shiftwidth=4: