POE/Aliased.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 89.7% 35 / 39 CC 5 SCAR 7.0
CC
5
Cov
91%
__ANON__
3.0
__ANON__
2.1
__ANON__
2.0
CRAP 2.0
« POE/Meta/Role.pm ↑ Summary POE/Meta/Trait/Class.pm »
1 package MooseX::POE::Aliased;
2 {
3 2 $MooseX::POE::Aliased::VERSION = '0.215';
4 }
5 # ABSTRACT: A sane alias attribute for your MooseX::POE objects.
6 2 ▶use MooseX::POE::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 has alias => (
13 isa => "Maybe[Str]",
14 is => "rw",
15 builder => "_build_alias",
16 clearer => "clear_alias",
17 predicate => "has_alias",
18 9 ▶ trigger => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
19 9 my ( $self, $alias ) = @_;
20  
21 # we cannot set the alias UNTIL we construct the object!
22 # or ASSERT_DEFAULT will complain...
23 9 ▶ return unless defined $self->get_session_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->get_session_id 5 4 9
24 4 $self->call( _update_alias => $alias );
25 }
26 2 );
27  
28 5 ▶before 'STARTALL' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
29 5 my ($self) = @_;
30  
31 5 ▶ $self->call( _update_alias => $self->alias )
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_alias 5 0 5
32 if $self->has_alias;
33 2 };
34  
35 0 ▶sub _build_alias {
Subroutine _build_alias: not called CC=1 SCAR=6.9
36 0 my $self = shift;
37 0 overload::StrVal($self);
38 }
39  
40 9 ▶event _update_alias => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
41 9 my ( $kernel, $self, $alias ) = @_[KERNEL, OBJECT, ARG0];
42  
43 # we need to remove the prev alias like this because we don't know the
44 # previous value.
45 9 $kernel->alias_remove($_) for $kernel->alias_list( $self->get_session_id );
46 9 ▶ $kernel->alias_set($alias) if defined $alias;
Branch: 1 branch
BranchTrueFalseTotal
if defined $alias 7 2 9
47  
48 9 return;
49 2 };
50  
51 2 __PACKAGE__;
52  
53  
54  
55 =pod
56  
57 =head1 NAME
58  
59 MooseX::POE::Aliased - A sane alias attribute for your MooseX::POE objects.
60  
61 =head1 VERSION
62  
63 version 0.215
64  
65 =head1 SYNOPSIS
66  
67 use MooseX::POE;
68  
69 with qw(MooseX::POE::Aliased);
70  
71 my $obj = Foo->new( alias => "blah" );
72  
73 $obj->alias("arf"); # previous one is removed, new one is set
74  
75 $obj->alias(undef); # no alias set
76  
77 =head1 DESCRIPTION
78  
79 This role provides an C<alias> attribute for your L<MooseX::POE> objects.
80  
81 The attribute can be set, causing the current alias to be cleared and the new
82 value to be set.
83  
84 =head1 METHODS
85  
86 =head2 alias
87  
88 The alias to set for the session.
89  
90 Defaults to the C<overload::StrVal> of the object.
91  
92 If the value is set at runtime the alias will be updated in the L<POE::Kernel>.
93  
94 A value of C<undef> inhibits aliasing.
95  
96 =head1 ATTRIBUTES
97  
98 =head1 AUTHORS
99  
100 =over 4
101  
102 =item *
103  
104 Chris Prather <chris@prather.org>
105  
106 =item *
107  
108 Ash Berlin <ash@cpan.org>
109  
110 =item *
111  
112 Chris Williams <chris@bingosnet.co.uk>
113  
114 =item *
115  
116 Yuval (nothingmuch) Kogman
117  
118 =item *
119  
120 Torsten Raudssus <torsten@raudssus.de> L<http://www.raudssus.de/>
121  
122 =back
123  
124 =head1 COPYRIGHT AND LICENSE
125  
126 This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus.
127  
128 This is free software; you can redistribute it and/or modify it under
129 the same terms as the Perl 5 programming language system itself.
130  
131 =cut
132  
133  
134 __END__
« POE/Meta/Role.pm ↑ Summary POE/Meta/Trait/Class.pm »