File Coverage

blib/lib/Global/Context/Stack.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition 3 3 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 22 23 95.6


line stmt bran cond sub pod time code
1             package Global::Context::Stack;
2             {
3             $Global::Context::Stack::VERSION = '0.003';
4             }
5 3     3   2150 use Moose::Role;
  3         5  
  3         24  
6             # ABSTRACT: the stack of a Global::Context::Env object
7              
8              
9             with 'MooseX::Clone';
10              
11 3     3   14852 use Moose::Util::TypeConstraints;
  3         7  
  3         31  
12              
13 3     3   5391 use namespace::autoclean;
  3         6  
  3         28  
14              
15             role_type('Global::Context::StackFrame');
16              
17             has frames => (
18             isa => 'ArrayRef[ Global::Context::StackFrame ]',
19             reader => '_frames',
20             traits => [ 'Array' ],
21             default => sub { [] },
22             handles => {
23             frames => 'elements',
24             current_frame => [ get => -1 ],
25             },
26             );
27              
28             sub with_pushed_frame {
29 5     5 0 8 my ($self, $frame) = @_;
30              
31 5         222 my @frames = $self->frames;
32 5 100 100     174 pop @frames if @frames and $frames[0]->is_ephemeral;
33              
34 5         90 $self->clone(frames => [ @frames, $frame ]);
35             }
36              
37             1;
38              
39             __END__
40              
41             =pod
42              
43             =head1 NAME
44              
45             Global::Context::Stack - the stack of a Global::Context::Env object
46              
47             =head1 VERSION
48              
49             version 0.003
50              
51             =head1 OVERVIEW
52              
53             Global::Context::Stack is a role.
54              
55             Stack objects provide information about the execution path that has led to the
56             current execution point in a program. It has only one important attribute,
57             C<frames>, which is an arrayref of L<Global::Context::StackFrame> objects.
58              
59             It provides one critical method, L<with_pushed_frame>, which returns a clone of
60             the stack with one addition frame added. (If the top frame of the stack was
61             "ephemeral," it is replaced instead of pushed down.)
62              
63             =head1 AUTHOR
64              
65             Ricardo Signes <rjbs@cpan.org>
66              
67             =head1 COPYRIGHT AND LICENSE
68              
69             This software is copyright (c) 2010 by Ricardo Signes.
70              
71             This is free software; you can redistribute it and/or modify it under
72             the same terms as the Perl 5 programming language system itself.
73              
74             =cut