| Lines 17-24
          package Koha::Objects;
      
      
        Link Here | 
        
          | 17 | # with Koha; if not, write to the Free Software Foundation, Inc., | 17 | # with Koha; if not, write to the Free Software Foundation, Inc., | 
        
          | 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 
        
          | 19 |  | 19 |  | 
            
              | 20 | use overload "0+" => "count", "<>" => "next", fallback => 1; |  |  | 
            
              | 21 |  | 
        
          | 22 | use Modern::Perl; | 20 | use Modern::Perl; | 
        
          | 23 |  | 21 |  | 
        
          | 24 | use Carp; | 22 | use Carp; | 
  
    | Lines 59-71
          sub new {
      
      
        Link Here | 
        
          | 59 |     bless( $self, $class ); | 57 |     bless( $self, $class ); | 
        
          | 60 | } | 58 | } | 
        
          | 61 |  | 59 |  | 
          
            
              | 62 | =head3 Koha::Objects->new_from_dbic(); | 60 | =head3 Koha::Objects->_new_from_dbic(); | 
        
          | 63 |  | 61 |  | 
          
            
              | 64 | my $object = Koha::Objects->new_from_dbic( $resultset ); | 62 | my $object = Koha::Objects->_new_from_dbic( $resultset ); | 
        
          | 65 |  | 63 |  | 
        
          | 66 | =cut | 64 | =cut | 
        
          | 67 |  | 65 |  | 
          
            
              | 68 | sub new_from_dbic { | 66 | sub _new_from_dbic { | 
        
          | 69 |     my ( $class, $resultset ) = @_; | 67 |     my ( $class, $resultset ) = @_; | 
        
          | 70 |     my $self = { _resultset => $resultset }; | 68 |     my $self = { _resultset => $resultset }; | 
        
          | 71 |  | 69 |  | 
  
    | Lines 84-90
          sub find {
      
      
        Link Here | 
        
          | 84 |  | 82 |  | 
        
          | 85 |     my $result = $self->_resultset()->find($id); | 83 |     my $result = $self->_resultset()->find($id); | 
        
          | 86 |  | 84 |  | 
          
            
              | 87 |     my $object = $self->object_class()->new_from_dbic( $result ); | 85 |     my $object = $self->object_class()->_new_from_dbic( $result ); | 
        
          | 88 |  | 86 |  | 
        
          | 89 |     return $object; | 87 |     return $object; | 
        
          | 90 | } | 88 | } | 
  
    | Lines 108-114
          sub search {
      
      
        Link Here | 
        
          | 108 |         my $class = ref($self) ? ref($self) : $self; | 106 |         my $class = ref($self) ? ref($self) : $self; | 
        
          | 109 |         my $rs = $self->_resultset()->search($params); | 107 |         my $rs = $self->_resultset()->search($params); | 
        
          | 110 |  | 108 |  | 
          
            
              | 111 |         return $class->new_from_dbic($rs); | 109 |         return $class->_new_from_dbic($rs); | 
        
          | 112 |     } | 110 |     } | 
        
          | 113 | } | 111 | } | 
        
          | 114 |  | 112 |  | 
  
    | Lines 126-132
          sub count {
      
      
        Link Here | 
        
          | 126 |  | 124 |  | 
        
          | 127 | =head3 Koha::Objects->next(); | 125 | =head3 Koha::Objects->next(); | 
        
          | 128 |  | 126 |  | 
          
            
              | 129 | my $object = Koha::Object->next(); | 127 | my $object = Koha::Objects->next(); | 
        
          | 130 |  | 128 |  | 
        
          | 131 | Returns the next object that is part of this set. | 129 | Returns the next object that is part of this set. | 
        
          | 132 | Returns undef if there are no more objects to return. | 130 | Returns undef if there are no more objects to return. | 
  
    | Lines 134-145
          Returns undef if there are no more objects to return.
      
      
        Link Here | 
        
          | 134 | =cut | 132 | =cut | 
        
          | 135 |  | 133 |  | 
        
          | 136 | sub next { | 134 | sub next { | 
          
            
              | 137 |     my ( $self, $id ) = @_; | 135 |     my ( $self ) = @_; | 
        
          | 138 |  | 136 |  | 
        
          | 139 |     my $result = $self->_resultset()->next(); | 137 |     my $result = $self->_resultset()->next(); | 
        
          | 140 |     return unless $result; | 138 |     return unless $result; | 
        
          | 141 |  | 139 |  | 
          
            
              | 142 |     my $object = $self->object_class()->new_from_dbic( $result ); | 140 |     my $object = $self->object_class()->_new_from_dbic( $result ); | 
        
          | 143 |  | 141 |  | 
        
          | 144 |     return $object; | 142 |     return $object; | 
        
          | 145 | } | 143 | } | 
  
    | Lines 154-160
          with the first object in a set.
      
      
        Link Here | 
        
          | 154 | =cut | 152 | =cut | 
        
          | 155 |  | 153 |  | 
        
          | 156 | sub reset { | 154 | sub reset { | 
          
            
              | 157 |     my ( $self, $id ) = @_; | 155 |     my ( $self ) = @_; | 
        
          | 158 |  | 156 |  | 
        
          | 159 |     $self->_resultset()->reset(); | 157 |     $self->_resultset()->reset(); | 
        
          | 160 |  | 158 |  | 
  
    | Lines 170-176
          Returns an arrayref of the objects in this set.
      
      
        Link Here | 
        
          | 170 | =cut | 168 | =cut | 
        
          | 171 |  | 169 |  | 
        
          | 172 | sub as_list { | 170 | sub as_list { | 
          
            
              | 173 |     my ( $self, $id ) = @_; | 171 |     my ( $self ) = @_; | 
        
          | 174 |  | 172 |  | 
        
          | 175 |     my @dbic_rows = $self->_resultset()->all(); | 173 |     my @dbic_rows = $self->_resultset()->all(); | 
        
          | 176 |  | 174 |  | 
  
    | Lines 181-194
          sub as_list {
      
      
        Link Here | 
        
          | 181 |  | 179 |  | 
        
          | 182 | =head3 Koha::Objects->_wrap | 180 | =head3 Koha::Objects->_wrap | 
        
          | 183 |  | 181 |  | 
          
            
              | 184 | wraps the DBIC object in a corrosponding Koha object | 182 | wraps the DBIC object in a corresponding Koha object | 
        
          | 185 |  | 183 |  | 
        
          | 186 | =cut | 184 | =cut | 
        
          | 187 |  | 185 |  | 
        
          | 188 | sub _wrap { | 186 | sub _wrap { | 
        
          | 189 |     my ( $self, @dbic_rows ) = @_; | 187 |     my ( $self, @dbic_rows ) = @_; | 
        
          | 190 |  | 188 |  | 
          
            
              | 191 |     my @objects = map { $self->object_class()->new_from_dbic( $_ ) } @dbic_rows; | 189 |     my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows; | 
        
          | 192 |  | 190 |  | 
        
          | 193 |     return @objects; | 191 |     return @objects; | 
        
          | 194 | } | 192 | } |