UEMColumn/Column.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Physics::UEMColumn::Column;
2  
3 =head1 NAME
4  
5 Physics::UEMColumn::Column - Class representing a column for the Physics::UEMColumn simulation
6  
7 =head1 SYNOPSIS
8  
9 use strict;
10 use warnings;
11  
12 use Physics::UEMColumn alias => ':standard';
13  
14 my $column = Column->new(
15 length => '100 cm',
16 );
17  
18 my $lens = MagneticLens->new(...);
19 $column->add_element($lens);
20  
21 =cut
22  
23 use Moose;
24 use namespace::autoclean;
25  
26 use Method::Signatures;
27 use MooseX::Types::NumUnit qw/num_of_unit/;
28  
29 =head1 ATTRIBUTES
30  
31 =over
32  
33 =item C<laser>
34  
35 Holder for an optional L<Physics::UEMColumn::Laser> object. Predicate: C<has_laser>.
36  
37 =cut
38  
39 has laser => ( isa => 'Physics::UEMColumn::Laser', is => 'ro', predicate => 'has_laser' );
40  
41 =item C<accelerator>
42  
43 Holder for an optional L<Physics::UEMColumn::Accelerator> object. Predicate: C<has_accelerator>.
44  
45 =cut
46  
47 has accelerator => (
48 isa => 'Physics::UEMColumn::Accelerator',
49 is => 'ro',
50 predicate => 'has_accelerator',
51 trigger => \&_trigger_accelerator,
52 );
53  
54 method _trigger_accelerator ($acc, $old_acc?) {
55 my $elements = $self->elements;
56  
57 if (eval{ $elements->[0]->isa('Physics::UEMColumn::Accelerator') }) {
58 shift @$elements;
59 }
60  
61 unshift @$elements, $acc;
62
63 }
64  
65 =item C<photocathode>
66  
67 Holder for an optional L<Physics::UEMColumn::Photocathode> object. Predicate: C<has_photocathode>.
68  
69 =cut
70  
71 has photocathode => (
72 isa => 'Physics::UEMColumn::Photocathode',
73 is => 'ro',
74 predicate => 'has_photocathode',
75 trigger => sub { $_[1]->column( $_[0] ) },
76 );
77  
78 =item C<elements>
79  
80 An array reference of all the elements in the column. This attribute should rarely be used directly, instead prefer the C<add_element> method.
81  
82 =cut
83  
84 has elements => (
85 traits => ['Array'],
86 isa => 'ArrayRef[Physics::UEMColumn::Element]',
87 is => 'rw',
88 handles => {
89 add_element => 'push',
90 },
91 default => sub{ [] },
92 );
93  
94 =item C<length>
95  
96 The length of the column. This value is required. This value defines then end of the simulation, in that when the pulse reaches the end of the column, the simulation is complete. Unit: meters.
97  
98 =cut
99  
100 has 'length' => ( isa => num_of_unit('m'), is => 'rw', required => 1 );
101  
102 =back
103  
104 =head1 METHODS
105  
106 =over
107  
108 =item C<add_element>
109  
110 Pushes a given L<Physics::UEMColumn::Element> object into the C<elements> attribute. Takes one or more such elements.
111  
112 =item C<can_make_pulse>
113  
114 Returns a true value if the column contains enough information to generate a pulse. This specifically means having all of a laser, accelerator, and photocathode objects. Note that should this method return false, a L<Physics::UEMColumn::Pulse> object will have to be manually created and given to the main simulation object (see L<Physics::UEMColumn>).
115  
116 =cut
117  
118 method can_make_pulse () {
119 return $self->has_laser && $self->has_accelerator && $self->has_photocathode;
120 }
121  
122 =back
123  
124 =cut
125  
126 __PACKAGE__->meta->make_immutable;
127  
128 1;
129  
130 =head1 SOURCE REPOSITORY
131  
132 L<http://github.com/jberger/Physics-UEMColumn>
133  
134 =head1 AUTHOR
135  
136 Joel Berger, E<lt>joel.a.berger@gmail.comE<gt>
137  
138 =head1 COPYRIGHT AND LICENSE
139  
140 Copyright (C) 2012-2013 by Joel Berger
141  
142 This library is free software; you can redistribute it and/or modify
143 it under the same terms as Perl itself.
144  
145