PrePAN

Sign in to PrePAN

Profile

djerius@github

GitHub: djerius PAUSE ID: djerius Bitbucket: djerius

User's Modules

Net::Object::Peer "Network" with pub/sub + direct peer-to-peer messaging

Net::Object::Peer is a Moo Role which implements a publish/subscribe peer-to-peer messaging system, based upon Beam::Emitter. Objects in the network may broadcast events to all subscribers or may send events to a particular subscriber.

Subscriptions and unsubscriptions are tracked and messages will be sent to affected objects upon request.

While Net::Object::Peer is designed around the concept of nodes being objects with methods as event handlers, it retains Beam::Emitter's ability to register code references as well.

Net::Object::Peer::Cookbook provides some recipes.

I'm not terribly enamored of the module name; suggestions for alternatives would be welcome!

djerius@github 0 comments

Sub::QuoteX::Utils Sugar for Sub::Quote

Sub::QuoteX::Utils provides a simplified interface to the process of combining Sub::Quote compatible code references with new code.

Sub::Quote provides a number of routines to make code more performant by inlining separate chunks of code into a single compiled subroutine.

When a chunk of code is compiled into a subroutine by Sub::Quote::quote_sub(), Sub::Quote keeps track of the code and any captured variables used to construct that subroutine, so that new code can be added to the original code and the results compiled into a new subroutine.

Sub::QuoteX::Utils makes that latter process a little easier.

djerius@github 0 comments

PDLx::Algorithm::Center Various ways of centering a dataset

This module collects various algorithms for determining the center of a dataset into one place. It accepts data stored as PDL variables (piddles)

Currently it contains a single function, sigma_clip, which provides an iterative algorithm which successively removes outliers by clipping those whose distances from the current center are greater than a given number of standard deviations.

sigma_clip finds the center of a data set by:

  1. ignoring the data whose distance to the current center is a specified number of standard deviations
  2. calculating a new center by performing a (weighted) centroid of the remaining data
  3. calculating the standard deviation of the distance from the data to the center
  4. repeat at step 1 until either a convergence tolerance has been met or the iteration limit has been exceeded

The initial center may be explicitly specified, or may be calculated by performing a (weighted) centroid of the data.

The initial standard deviation is calculated using the initial center and either the entire dataset, or from a clipped region about the initial center.

sigma_clip can center sparse (e.g., input is a list of coordinates) or dense datasets (input is a hyper-rectangle) with or without weights. It accepts a mask which directs it to use only certain elements in the dataset.

The coordinates may be transformed using (PDL::Transform)[https://metacpan.org/pod/PDL::Transform]. This is mostly useful for dense datasets, where coordinates are generated from the indices of the passed hyper-rectangle. This functionality is not currently documented, as tests for it have not yet been written.

More information is available at the github repo page, https://github.com/djerius/PDLx-Algorithm-Center

djerius@github 0 comments

Module::Build::Pluggable::AuthorTests Plugin to Module::Build to add author tests

This Module::Build::Pluggable plugin adds an authortest action which recursively runs tests in both the normal test directory t, as well as in author-only test directories (by default xt ).

To specify alternate author-only test directories, pass the "test_dirs" option when loading the module, e.g.

use Module::Build::Pluggable ( AuthorTests =>
                                { test_dirs => 'xtt' } );

"test_dirs" will accept either a scalar or an array of directories.

To run the tests,

./Build authortest

djerius@github 0 comments

MooX::Cmd::ChainedOptions Easy access to options up the chain of commands

When used instead of MooX::Options in applications constructed with MooX::Cmd, this class adds attributes to a command object which provide access to command line options passed to commands higher up the command chain.

For example (using the above code which creates an application and a command), the following command line

app --app-opt=FOO cmd --cmd-opt=BAR

would result in the MyApp::Cmd::cmd object having an attribute called app_opt which contains FOO.

Without this module, the MyApp::Cmd::cmd object would have to search through the chain of commands (passed to the execute method, or available via the command_chainmethod)looking for the app_opt attribute.

I'm afraid the name may be confused with "chained" method approaches, but MooX::Cmd uses the "chain" terminology to describe the hierarchy of commands, so I thought I'd stick to that.

Any alternate suggestions?

Thanks, Diab

djerius@github 0 comments

MooX::TaggedAttributes Add tags w/ values to Moo attributes

This module allows one to apply tags with values to attributes in Moo classes and Roles. Why?

Well, in my case I want to able to label attributes so that I can programatically find those with a particular label and operate on them.

For example, let's say that my class has attributes which are PDL objects (or piddles, as we call 'em), and I want to apply a transform just to those objects. Without tags, I'd have to know ahead of time which attributes were PDL objects, and which weren't. That might get complicated if I compose a bunch of roles (especially onto objects at run time).

With tagged attributes, I can do this:

package PDL::Tag;
use Moo::Role;
use MooX::TaggedAttributes -tags => 'piddle';

package MyClass;
use Moo;
use PDL::Tag;

has a => ( is => 'ro' );
has b => ( is => 'ro', piddle => 1 );

my $obj = MyClass->new( ... );

# search for attributes marked as piddles:
my @piddles = keys %{ $obj->_tags->{piddle} };

# and now do some Cool PDL stuff on 'em
$obj->$_->rotate(-1) for @piddles.

I could scan the attributes looking for a particular type, but tags are more elegant, and since they are arbitrary, can encode more information. The tag values are also arbitrary, so you can do anything you want with 'em.

djerius@github 3 comments

Data::Record::Serialize encode and write records with record munging

I found myself in the situation where I needed to output a stream of records (where a record is a set of fields composed of key, scalar value pairs) in a variety of formats (json, yaml, sqlite db) and needed to programmatically select a subset of the fields, sometimes format the values for human readability, etc.

This module stands out from others (well, I found one, Data::Serializer) in that it

  • allows one to rename fields
  • provides type information to encoders that can use it (such as writing to a database)
  • formats fields based on name or type
  • numify values that have been inadvertently not numified
  • allows encoders to write enclosing metadata (such as header records)

The module is only usable with "flat" data structures (no nested hashes or arrays) which are homogeneous in structure.

djerius@github 0 comments

Devel::ParseXS Parse XS files into an abstract syntax tree

I have a need to manipulate XS files, and it'd be a lot easier to do so if one could parse them into an abstract format for further manipulation.

ExtUtils::ParseXS is a masterfully woven tapestry, but it because it weaves parsing, interpretation and code generation into a single pass, it's hard to use it to create an abstract representation.

This led me to develop Devel::ParseXS and it's companion modules in the Devel::XS::AST namespace. The parsing code closely follows the perlxs documentation, and where necessary I've used the existing behavior of ExtUtils::ParseXS to disambiguate a few things.

Currently the parsing is pretty complete; not everything is further translated into a useable AST object. Prior to releasing this to CPAN, I'd like to get some feedback on the module names.

Devel::ParseXS and Devel::XS::AST sound good to me.

djerius@github 7 comments

subpackage DWIM nested package namespace

It can get tiresome declaring long nested package names. The subpackage pragma introduces a new subpackage keyword which works exactly like package, except that it prepends the current package name to the new package.

Here's the actual prototype code for subpackage.pm:

package subpackage;

use Keyword::Simple;

sub import {

    my $caller = caller;

    Keyword::Simple::define 'subpackage', sub {

    my ( $ref ) = @_;

    ${$ref} =~ s/^\s+(\w+)/package ${caller}::${1}/;
    };


}

sub unimport {

    Keyword::Simple::undefine 'subpackage';

}

1;

(To be honest, I'm positive that I'm reinventing the wheel here.)

djerius@github 0 comments

pkg transparently use packages and inner packages

Inner packages aren't well supported by most Perl pragmata. Most everything equates a package with a module. The only pragma that I know of that gives a nod in their direction is parent, which provides the -norequire option to prevent attempts at loading inner packages (which would fail).

I ran into this problem when I was creating a nested hierarchy of exception classes (by hand, not using Exception::Class). The classes themselves are essentially empty (simply inheriting from their parents), so for easy code maintenance and use I put them into a single file. Unfortunately, the names tend to get long, so I wanted to use the aliased pragma to shorten them. Unfortunately it doesn't support inner packages.

I ran into another problem with inner packages that export symbols; you need to explicitly import them using Inner::Class->import().

I started out writing patches for some of the existing pragmata, but decided it was easier to solve the problem in one spot. To that end I've implemented the pkg pragma to act as a front end to using packages. It uses Class:: Load to recognize inner packages, and Import::Into to provide importation. I tossed in class aliasing (based on aliased, but also see as), and multiple module loading (see also use).

I've tried to keep the syntax simple but flexible, so that more functionality is easily added to it.

djerius@github 5 comments