Fey/Role/MakesAliasObjects.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 86.3% 38 / 44 CC 3 SCAR 4.7
CC
3
Cov
86%
__ANON__
2.5
alias
2.5
__ANON__
1.0
CRAP 1.6
« Fey/Role/ColumnLike.pm ↑ Summary Fey/Role/HasAliasName.pm »
1 package Fey::Role::MakesAliasObjects;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.42';
8  
9 25 ▶use Fey::Types qw( ClassName Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 25 ▶use MooseX::Role::Parameterized 0.04;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 parameter 'alias_class' => (
14 is => 'ro',
15 isa => ClassName,
16 required => 1,
17 );
18  
19 6 parameter 'self_param' => (
20 is => 'ro',
21 isa => Str,
22 required => 1,
23 );
24  
25 6 parameter 'name_param' => (
26 is => 'ro',
27 isa => Str,
28 default => 'alias_name',
29 );
30  
31 role {
32 50 ▶ my $p = shift;
Subroutine __ANON__: called CC=1 SCAR=0.4
33  
34 50 my $alias_class = $p->alias_class();
35 50 my $self_param = $p->self_param();
36 50 my $name_param = $p->name_param();
37  
38 method 'alias' => sub {
39 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=2 SCAR=9.2
Subroutine alias: called CC=2 SCAR=9.2
40 0 ▶ my %p = @_ == 1 ? ( $name_param => $_[0] ) : @_;
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
@_ == 1 ? : 1 23 24
41  
42 0 return $alias_class->new( $self_param => $self, %p );
43 50 };
44 6 };
45  
46 6 1;
47  
48 # ABSTRACT: A role for objects with separate alias objects
49  
50 __END__
51  
52 =pod
53  
54 =head1 NAME
55  
56 Fey::Role::MakesAliasObjects - A role for objects with separate alias objects
57  
58 =head1 VERSION
59  
60 version 0.42
61  
62 =head1 SYNOPSIS
63  
64 package My::Thing;
65  
66 use Moose 0.90;
67  
68 with 'Fey::Role::MakesAliasObjects'
69 => { alias_class => 'My::Alias',
70 self_param => 'thing',
71 name_param => 'alias_name',
72 };
73  
74 =head1 DESCRIPTION
75  
76 This role adds a "make an alias object" method to a class. This is for
77 things like tables and columns, which can have aliases.
78  
79 =head1 PARAMETERS
80  
81 =head2 alias_class
82  
83 The name of the class whose C<new()> is called by the C<alias()>
84 method (see below). Required.
85  
86 =head2 self_param
87  
88 The name of the parameter to pass C<$self> to the C<alias_class>'
89 C<new()> method as. Required.
90  
91 =head2 name_param
92  
93 The name of the parameter to C<alias()> that passing a single string
94 is assumed to be. Defaults to C<alias_name>.
95  
96 =head1 METHODS
97  
98 =head2 $obj->alias()
99  
100 my $alias = $obj->alias(alias_name => 'an_alias', %other_params);
101  
102 my $alias = $obj->alias('an_alias');
103  
104 Create a new alias for this object. If a single parameter is
105 provided, it is assumed to be whatever the C<name_param> parameter
106 specifies (see above).
107  
108 =head1 BUGS
109  
110 See L<Fey> for details on how to report bugs.
111  
112 =head1 AUTHOR
113  
114 Dave Rolsky <autarch@urth.org>
115  
116 =head1 COPYRIGHT AND LICENSE
117  
118 This software is Copyright (c) 2011 - 2015 by Dave Rolsky.
119  
120 This is free software, licensed under:
121  
122 The Artistic License 2.0 (GPL Compatible)
123  
124 =cut
« Fey/Role/ColumnLike.pm ↑ Summary Fey/Role/HasAliasName.pm »