| 1 | package MooseX::Atom; | ||||||||||
| 2 | |||||||||||
| 3 | # See end of file for docs | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.008005; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Moose 1.08 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | our $VERSION = '0.02'; | |||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=6 SCAR=18.2
| |||||||||||
| 13 | 1 | my $class = shift; | |||||||||
| 14 | 1 | my @model = @{ pop() }; | |||||||||
| 15 | 1 | my $package = caller(); | |||||||||
| 16 | |||||||||||
| 17 | # Generate the metaobject, and immediately remove all the exported symbols. | ||||||||||
| 18 | # This is a hack until I can work out how to avoid exporting them at all. | ||||||||||
| 19 | # NOTE: Yuck! | ||||||||||
| 20 | 1 | ▶ | eval "package $package; use Moose; no Moose;"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | die $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | # Push the commands to generate the class directly through the meta object. | ||||||||||
| 24 | 1 | my $meta = $package->meta; | |||||||||
| 25 | 1 | my @with = (); | |||||||||
| 26 | 1 | ▶ | while ( @model ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1 | my $command = shift @model; | |||||||||
| 28 | 1 | my $params = shift @model; | |||||||||
| 29 | 1 | ▶ | $params = [ $params ] unless ref $params eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 1 | ▶ | if ( $command eq 'with' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | push @with, $params; | |||||||||
| 32 | 0 | next; | |||||||||
| 33 | } | ||||||||||
| 34 | 2 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 1 | &{"Moose::$command"}( $meta, @$params ); | |||||||||
| 36 | } | ||||||||||
| 37 | 1 | foreach my $params ( @with ) { | |||||||||
| 38 | 0 | Moose::with( $meta, @$params ); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # Immediately make the class immutable | ||||||||||
| 42 | 1 | $meta->make_immutable; | |||||||||
| 43 | |||||||||||
| 44 | 1 | return 1; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 2 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||