CatalystX::Features::Feature - Class that represents a single feature.


CatalystX-Features documentation Contained in the CatalystX-Features distribution.

Index


Code Index:

NAME

Top

CatalystX::Features::Feature - Class that represents a single feature.

VERSION

Top

version 0.20

SYNOPSIS

Top

    foreach my $feature( $c->features ) {
        $c->log->info( $feature->name );  # $feature methods declared here
    }

DESCRIPTION

Top

This is the object you get when you list features with $c->features.

METHODS

Top

This is how this class implements the required interfaces from the role CatalystX::Features::Role::Feature.

id

For a feature directory of "my.feature_1.0", the id part is "my.feature_1.0".

name

For a feature directory of "my.feature_1.0", the name is "my.feature".

version

For a feature directory of "my.feature_1.0", the version is "1.0".

version_number

A version long integer that can be compared easily. For a feature directory of "my.feature_1.2.3", the version number equals 001002003.

TODO

Top

Change the base class name thru config

Not everyone want to have this object as a base class for their features. There is a role (interface) already created in case you want to create your own class from scratch.

AUTHORS

Top

	Rodrigo de Oliveira (rodrigolive), C<rodrigolive@gmail.com>

LICENSE

Top

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.


CatalystX-Features documentation Contained in the CatalystX-Features distribution.

package CatalystX::Features::Feature;
$CatalystX::Features::Feature::VERSION = '0.20';
use Moose;
use Path::Class;
use Catalyst::Utils;

has 'backend' => ( is=>'ro', isa=>'CatalystX::Features::Role::Backend', weak_ref=>1, required=>1 );

has 'id'      => ( is => 'rw', isa => 'Str' );
has 'name'    => ( is => 'rw', isa => 'Str' );
has 'version' => ( is => 'rw', isa => 'Str', default => 'max' );
has 'path'    => ( is => 'rw', isa => 'Str', trigger => \&_build_from_path );

has 'root' => ( is => 'rw', isa => 'Str' );
has 'lib'  => ( is => 'rw', isa => 'Str' );
has 't'    => ( is => 'rw', isa => 'Str' );

with 'CatalystX::Features::Role::Feature';  # the interface role, place after 'has'

sub _build_from_path {
    my ($self, $value ) = @_;

    my $path = $self->path; 
    my $full_path = Path::Class::dir( $path ); 
    my $id = $full_path->relative( $full_path->parent )->stringify;

    my ($name,$version) = ( $id =~ /^(.*?)[_|-](.*?)$/ );

    $self->id( $id );
    $self->name( $name || $id );
    $version && $self->version( $version );

    $self->root( Path::Class::dir( $self->path . "/root" )->stringify );
    $self->lib( Path::Class::dir( $self->path . "/lib" )->stringify );
    $self->t( Path::Class::dir( $self->path . "/t" )->stringify );
}

sub version_number {
    my $self = shift;
    my $version = $self->version;
    if( $version =~ /\./ ) {
        my $number;
        foreach my $part ( split /\./, $version ) {
            $number .= sprintf("%099d", $part );
        }
        return $number;
    } else {
        return $version;
    }
}

sub config {
    my $self = shift;

	$self->backend->config->{ $self->name };

}

1;

__END__