SPOPS/Tool/ReadOnly.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 49 CC 1 SCAR 6.9
CC
1
Cov
0%
behavior_factory
2.0
generate_persistence_methods
2.0
BEGIN
2.0
CRAP 2.0
1 package SPOPS::Tool::ReadOnly;
2  
3 # $Id: ReadOnly.pm,v 3.3 2004/06/02 00:48:24 lachoy Exp $
4  
5 use strict;
6 use Log::Log4perl qw( get_logger );
7 use SPOPS;
8 use SPOPS::ClassFactory qw( OK );
9  
10 my $log = get_logger();
11  
12 $SPOPS::Tool::ReadOnly::VERSION = sprintf("%d.%02d", q$Revision: 3.3 $ =~ /(\d+)\.(\d+)/);
13  
14 sub behavior_factory {
15 my ( $class ) = @_;
16 $log->is_info &&
17 $log->info( "Installing read-only persistence methods for ($class)" );
18 return { read_code => \&generate_persistence_methods };
19 }
20  
21 sub generate_persistence_methods {
22 my ( $class ) = @_;
23 $log->is_info &&
24 $log->info( "Generating read-only save() and remove() for ($class)" );
25 no strict 'refs';
26 *{ "${class}::save" } =
27 sub {
28 SPOPS::Exception->throw( ref $_[0], " is read-only; no changes allowed" );
29 };
30 *{ "${class}::remove" } =
31 sub {
32 SPOPS::Exception->throw( ref $_[0], " is read-only; no changes allowed" );
33 };
34 return OK;
35 }
36  
37 1;
38  
39 __END__