File Coverage

lib/Workflow/Context.pm
Criterion Covered Total %
statement 16 17 94.1
branch n/a
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 23 24 95.8


line stmt bran cond sub pod time code
1              
2             use warnings;
3 21     21   602 use strict;
  21         40  
  21         701  
4 21     21   98 use base qw( Workflow::Base );
  21         25  
  21         548  
5 21     21   108  
  21         40  
  21         4597  
6             $Workflow::Context::VERSION = '1.61';
7              
8              
9             my ( $self, %params) = @_;
10              
11 27     27 1 57 for my $key (keys %params) {
12             $self->param( $key => $params{$key} );
13 27         94 }
14 0         0 }
15              
16             my ( $self, $other ) = @_;
17             my $other_params = $other->param();
18             while ( my ( $k, $v ) = each %{$other_params} ) {
19 1     1 1 31 $self->param( $k, $v );
20 1         3 }
21 1         2 }
  2         8  
22 1         2  
23             1;
24              
25              
26             =pod
27              
28             =head1 NAME
29              
30             Workflow::Context - Data blackboard for Workflows, Actions, Conditions and Validators
31              
32             =head1 VERSION
33              
34             This documentation describes version 1.61 of this package
35              
36             =head1 SYNOPSIS
37              
38             # Create your own context and merge it with one that may already be
39             # in a workflow
40              
41             my $context = Workflow::Context->new();
42             $context->param( foo => 'bar' );
43             $context->param( current_user => User->fetch( 'foo@bar.com' ) );
44             my $wf = FACTORY()->create_workflow( 'w/f', $context );
45              
46             # The above is the same as:
47             $context = Workflow::Context->new(
48             foo => 'bar',
49             current_user => User->fetch( 'foo@bar.com' ),
50             );
51             $wf = FACTORY()->create_workflow( 'w/f', $context );
52              
53              
54             # In a Condition get the 'current_user' back out of the workflow's context
55              
56             sub evaluate {
57             my ( $self, $wf ) = @_;
58             my $current_user = $wf->context->param( 'current_user' );
59             ...
60             }
61              
62             # Set values directly into a workflow's context
63              
64             $wf->context->param( foo => 'bar' );
65             $wf->context->param( news => My::News->fetch_where( 'date = ?', DateTime->now ) );
66              
67             =head1 DESCRIPTION
68              
69             Holds information to pass between your application and a Workflow,
70             including its Actions, Conditions and Validators.
71              
72             =head1 OBJECT METHODS
73              
74             =head2 init( %params )
75              
76             Adds C<%params> to the context at instantiation.
77              
78             =head2 merge( $other_context )
79              
80             Merges the values from C<$other_context> into this object. If there
81             are duplicate keys in this object and C<$other_context>,
82             C<$other_context> wins.
83              
84             =head1 SEE ALSO
85              
86             =over
87              
88             =item * L<Workflow>
89              
90             =back
91              
92             =head1 COPYRIGHT
93              
94             Copyright (c) 2003-2022 Chris Winters. All rights reserved.
95              
96             This library is free software; you can redistribute it and/or modify
97             it under the same terms as Perl itself.
98              
99             Please see the F<LICENSE>
100              
101             =head1 AUTHORS
102              
103             Please see L<Workflow>
104              
105             =cut