Acme::PlayCode::Plugin::Averything - A is Ace, All, Averything


Acme-PlayCode documentation Contained in the Acme-PlayCode distribution.

Index


Code Index:

NAME

Top

Acme::PlayCode::Plugin::Averything - A is Ace, All, Averything

SYNOPSIS

Top

    use Acme::PlayCode;

    my $app = new Acme::PlayCode;

    # load all plugins we find at the dir of this module sits.
    $app->load_plugin('Averything');

    my $played_code = $app->play( $code );
    # or
    my $played_code = $app->play( $filename );
    # or
    $app->play( $filename, { rewrite_file => 1 } ); # override $filename with played code

DESCRIPTION

Top

Load all plugins find at lib/Acme/PlayCode/Plugin/.

SEE ALSO

Top

Acme::PlayCode, Moose, PPI, MooseX::Object::Pluggable

AUTHOR

Top

Fayland Lam, <fayland at gmail.com>

COPYRIGHT & LICENSE

Top


Acme-PlayCode documentation Contained in the Acme-PlayCode distribution.

package Acme::PlayCode::Plugin::Averything;

use Moose::Role;
use Path::Class ();

our $VERSION   = '0.10';
our $AUTHORITY = 'cpan:FAYLAND';

use vars qw/$avreything_loaded/;

around 'play' => sub {
    my $orig = shift;
    my $self = shift;

    $avreything_loaded = 0 unless (defined $avreything_loaded);
    unless ( $avreything_loaded ) {
        my @all_plugins;
        my $path = __FILE__;
        $path =~ s/Averything\.pm//isg;
        my $dir = Path::Class::Dir->new($path);
        my $handle = $dir->open;
        while (my $file = $dir->next) {
            $file = $file->stringify;
            next if ( $file !~ /\.pm$/ );
            ( undef, my $basename ) = ( $file =~ /^(.*?)Plugin\S(.*?)$/is );
            $basename =~ s/\.pm$//isg;
            $basename =~ s/[\\\/]/\:\:/isg;
            next if ( $basename eq 'Averything');
            push @all_plugins, $basename;
        }
        @all_plugins = sort @all_plugins;
        $self->load_plugins(@all_plugins);
        $avreything_loaded = 1;
    }

    $orig->($self, @_);
};

no Moose::Role;

1;
__END__