Changeset 0faedb747c77b2da4f5aa97abc381a4984c861a7 in xas-model


Ignore:
Timestamp:
02/25/15 16:51:58 (5 years ago)
Author:
Kevin L. Esteb <kevin@…>
Branches:
master
Children:
7d602a7b80b217f0f5a162bde18ef9848faf32f2
Parents:
0e20d6d6a724f20fc2a5f11ca05c8f3a77208599
git-author:
Kevin L. Esteb <kevin@…> (02/25/15 16:51:58)
git-committer:
Kevin L. Esteb <kevin@…> (02/25/15 16:51:58)
Message:

Fixed a logic problem and added a delete_records() method.

Location:
trunk/lib/XAS/Model
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/XAS/Model/DBM.pm

    rfc5d23c129b6246a6eb88d5f78fdde934718e237 r0faedb747c77b2da4f5aa97abc381a4984c861a7  
    140140} 
    141141 
     142sub delete_records { 
     143    my $class  = shift; 
     144    my $schema = shift; 
     145 
     146    $schema->txn_do(sub {  
     147 
     148        if (my $rs = $class->search($schema, @_)) { 
     149 
     150            while (my $row = $rs->next) { 
     151 
     152                $row->delete(); 
     153 
     154            } 
     155 
     156        } 
     157 
     158    }); 
     159 
     160} 
     161 
    142162sub read_record { 
    143163    my $class    = shift; 
     
    536556=back 
    537557 
     558=head2 delete_records($class, $schema, ...) 
     559 
     560This method will delete records based on the passed criteria.  
     561It takes two or more parameters: 
     562 
     563=over 4 
     564 
     565=item B<$class> 
     566 
     567The DBIx::Class model name. Usually a constant defined within XAS::Model::Database. 
     568 
     569=item B<$schema>  
     570 
     571The DBIx::Class schema handle returned from opendb() in XAS::Model::Database. 
     572 
     573=item B<...> 
     574 
     575Other parameters that are passed directly to the search() method. 
     576 
     577=back 
     578 
    538579=head2 read_record($class, $schema, ...) 
    539580 
  • trunk/lib/XAS/Model/Database.pm

    r8f14efda2486086620dae33eba4e05b4cdfa98e1 r0faedb747c77b2da4f5aa97abc381a4984c861a7  
    55use Class::Inspector; 
    66use XAS::Model::Schema; 
     7use Params::Validate qw/SCALAR ARRAYREF/; 
    78 
    89use XAS::Class 
     
    1011  version    => $VERSION, 
    1112  base       => 'XAS::Base', 
    12   constants  => 'DELIMITER PKG REFS ONCE HASH ARRAY', 
     13  constants  => 'DELIMITER PKG REFS ARRAY', 
    1314  filesystem => 'File', 
    1415  exports => { 
     
    2324our $KEYS; 
    2425   
    25 use Data::Dumper; 
     26#use Data::Dumper; 
    2627 
    2728# --------------------------------------------------------------------- 
     
    3334    my $target = shift; 
    3435    my $symbol = shift; 
    35     my $tables = @_ == 1 ? shift : [ @_ ]; 
    36  
    37     $self->tables($tables); 
     36    my $tables = shift; 
     37 
     38    $self->tables($tables, 4); 
    3839 
    3940    return $self; 
     
    4546    my $target  = shift; 
    4647    my $symbol  = shift; 
    47     my $schemas = @_ == 1 ? shift : [ @_ ]; 
     48    my $schemas = shift; 
    4849 
    4950    $self->schemas($schemas); 
     
    5657# Public Methods 
    5758# --------------------------------------------------------------------- 
     59 
     60sub table { 
     61    my $self = shift; 
     62 
     63    $self->tables(@_); 
     64 
     65} 
    5866 
    5967sub tables { 
    6068    my $self = shift; 
    61     my ($tables) = $self->validate_params(\@_, [1]); 
     69    my ($tables, $depth) = $self->validate_params(\@_, [ 
     70        { type     => SCALAR | ARRAYREF }, 
     71        { optional => 1, default => 3 }, 
     72    ]); 
    6273 
    6374    $tables = [ split(DELIMITER, $tables) ] unless (ref($tables) eq ARRAY); 
    6475 
    65     my ($pkg) = caller(4); 
    66        
    67     no strict "refs";               # to register new methods in package 
     76    my ($pkg) = caller($depth);     # presummed caller 
     77 
     78    no strict REFS;                 # to register new methods in package 
    6879    no warnings;                    # turn off warnings 
    6980 
     
    94105sub schemas { 
    95106    my $self = shift; 
    96     my ($schemas) = $self->validate_params(\@_, [1]); 
     107    my ($schemas) = $self->validate_params(\@_, [ 
     108        { type => SCALAR | ARRAYREF }, 
     109    ]); 
    97110 
    98111    $schemas = [ split(DELIMITER, $schemas) ] unless (ref($schemas) eq ARRAY); 
Note: See TracChangeset for help on using the changeset viewer.