Sawyer X > Data-Collector-0.15 > Data::Collector::Info

Download:
Data-Collector-0.15.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.15   Source  

NAME ^

Data::Collector::Info - A base class for information classes

VERSION ^

version 0.15

SYNOPSIS ^

    package Data::Collector::Info::Bamba;
    use Moose;
    extends 'Data::Collector::Info';

    sub info_keys { ['bamba'] }

    sub _build_raw_data {
        my $self   = shift;
        my $engine = $self->engine;

        return $engine->run(/usr/bin/bamba-counter);
    }

    sub all {
        my $self = shift;
        return $self->raw_data;
    }

This synopsis shows how to create your own piece of info (in this case it counts bambas (which is a peanut snack).

REGISTRY ^

Since all info modules return values which are all gathered in a single hash, they might step on each other's toes. In order to avoid this, there is a registry that keeps all the keys from each info module. If you create an info module, you should register your keys in the registry. This is best done while subclassing the load method as shown in the synopsis.

ATTRIBUTES ^

raw_data

This contains the data received from the engine. You should implement a builder for it under the name _build_raw_data.

engine

This contains the object of the engine the info module would be using to fetch information. This is set by Data::Collector on initialize.

SUBROUTINES/METHODS ^

register

This method registers keys in the registry. You can provide as many as you want.

It should be called using the class, not any object, as such:

    Data::Collector::Info->register('bamba_count');

Now if anyone else will try to register another key (such as another bamba module), Data::Collector::Info will prevent it from happening.

unregister

This method can be used to remove keys from the registry. However, refrain from using this method in order to provide two collections. The reason is that there is still a boolean in Data::Collector that will stll prevent you from running another collection.

clear_registry

This method ostensibly clears all keys from the registry. In actuality, it simply replaces the existing registry with a new one.

info_keys

This method will run before an information module is loaded. You should subclass this method to indicate what keys you're going to acquire.

Any type of data other than an arrayref will be ignored.

You must subclass this method or your code will die.

load

This method will run when an information module is loaded. You should subclass this method if you're writing an info module that requires some extra bells and whistles you could use this method.

However, you do not have to subclass it.

all

This method is run to get all the information attainable by the info module.

If you have several bits of information in your module, you can have methods for each, but they should all be attainable using the all method.

You must subclass this method or your code will die.

BUILD

This is a Moose method which is done after module initialization. It's set to run the load method of the module. However, if you wish to do something else, you could subclass it.

Unless you're pulling off something especially fancy, subclass the load and use that instead - for the sake of clarity if not anything else.

AUTHOR ^

Sawyer X <xsawyerx@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Sawyer X.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: