[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4925] trunk/LedgerSMB



Revision: 4925
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4925&view=rev
Author:   einhverfr
Date:     2012-06-20 02:29:00 +0000 (Wed, 20 Jun 2012)
Log Message:
-----------
porting File.pm etc to Moose

Modified Paths:
--------------
    trunk/LedgerSMB/File/Order.pm
    trunk/LedgerSMB/File/Part.pm
    trunk/LedgerSMB/File/Transaction.pm
    trunk/LedgerSMB/File.pm

Modified: trunk/LedgerSMB/File/Order.pm
===================================================================
--- trunk/LedgerSMB/File/Order.pm	2012-06-19 13:28:05 UTC (rev 4924)
+++ trunk/LedgerSMB/File/Order.pm	2012-06-20 02:29:00 UTC (rev 4925)
@@ -24,7 +24,8 @@
 
 package LedgerSMB::File::Order;
 use strict;
-use base qw(LedgerSMB::File);
+use Moose;
+extends 'LedgerSMB::File';
 
 =head1 METHODS
 

Modified: trunk/LedgerSMB/File/Part.pm
===================================================================
--- trunk/LedgerSMB/File/Part.pm	2012-06-19 13:28:05 UTC (rev 4924)
+++ trunk/LedgerSMB/File/Part.pm	2012-06-20 02:29:00 UTC (rev 4925)
@@ -22,8 +22,8 @@
 =cut
 
 package LedgerSMB::File::Part;
-use strict;
-use base qw(LedgerSMB::File);
+use Moose;
+extends 'LedgerSMB::File';
 
 =head1 METHODS
 

Modified: trunk/LedgerSMB/File/Transaction.pm
===================================================================
--- trunk/LedgerSMB/File/Transaction.pm	2012-06-19 13:28:05 UTC (rev 4924)
+++ trunk/LedgerSMB/File/Transaction.pm	2012-06-20 02:29:00 UTC (rev 4925)
@@ -20,8 +20,8 @@
 =cut
 
 package LedgerSMB::File::Transaction;
-use strict;
-use base qw(LedgerSMB::File);
+use Moose;
+extends 'LedgerSMB::File';
 
 =back
 

Modified: trunk/LedgerSMB/File.pm
===================================================================
--- trunk/LedgerSMB/File.pm	2012-06-19 13:28:05 UTC (rev 4924)
+++ trunk/LedgerSMB/File.pm	2012-06-20 02:29:00 UTC (rev 4925)
@@ -1,4 +1,4 @@
-=pod
+=pod 
 
 =head1 NAME
 
@@ -17,20 +17,26 @@
 
 
 package LedgerSMB::File;
-use Class::Struct;
-use LedgerSMB::DBObject;
+use Moose;
+extends 'LedgerSMB::DBObject_Moose';
 use File::MimeInfo;
-#use IO::Scalar;
-use strict;
 
 =item  attached_by_id
 
 Entity id of the individual who attached the file.
 
+=cut
+
+has attached_by_id => (is => 'rw', isa => 'Maybe[Int]');
+
 =item attached_by
 
 Entity name of individual who attached file
 
+=cut
+
+has attached_by => (is => 'rw', isa => 'Maybe[Str]');
+
 =item attached_at 
 
 Timestamp of attachment point.
@@ -39,198 +45,119 @@
 
 This stores the binary content of the file.
 
+=cut
+
+has content => (is => 'rw', isa => 'Any');
+
 =item mime_type_id
 
 ID of the MIME type.  Undef if unknown.
 
+=cut
+
+has mime_type_id => (is => 'rw', isa => 'Maybe[Int]');
+
 =item mime_type_text
 
 Standard text code of the MIME type
 
+=cut
+
+has mime_type_text => (is => 'rw', isa => 'Maybe[Str]');
+
 =item file_name
 
 File name, user specified
 
+=cut
+
+has file_name => (is => 'rw', isa => 'Str');
+
 =item description
 
 Description, user specified
 
+=cut
+
+has description => (is => 'rw', isa => 'Maybe[Str]');
+
 =item id
 
 ID of file.  undef if unknown
 
+=cut
+
+has id => (is => 'rw', isa => 'Maybe[Int]');
+
 =item ref_key
 
 Referential key for the file to attach to.
 
+=cut
+
+has ref_key => (is => 'rw', isa => 'Int');
+
 =item reference
 
 Reference control code (text string) for attached financial database object.
 
+=cut
+
+has reference => (is => 'rw', isa => 'Maybe[Str]');
+
 =item file_class
 
 ID of the file class.
 
+=cut
+
+has file_class => (is => 'rw', isa => 'Int');
+
 =item src_class
 
 ID of class of the original attachment point (for a link)
 
+=cut
+
+has src_class => (is => 'rw', isa => 'Maybe[Int]');
+
 =item file_path
 
 Path, relative to $LedgerSMB::tempdir, where file data is stored (for LaTeX use
 of attached images).
 
-=item dbobject
+=cut
 
-Object for db interface.
+has file_path => (is => 'rw', isa => 'Maybe[Str]');
 
 =item sizex
 
 X axis dimensions, if Image::Size is installed and file is image (only on files
 retrieved for invoices).
 
+=cut
+
+has sizex => (is => 'rw', isa => 'Maybe[Int]');
+
 =item sizey
 
 Y axis dimensions, if Image::Size is installed and file is image (only on files
 retrieved for invoices).
 
-=item x_info
+=cut
 
-A hash for extended information
+has sizey => (is => 'rw', isa => 'Maybe[Int]');
 
-Note additionally the $self hashref contains the basic required attributes for
-DBObject, namely dbh, _roles, and _locale. 
-
 =back
 
 =cut
 
-struct 'LedgerSMB::File' => {
-   attached_by_id =>  '$',
-   attached_by    =>  '$',
-   attached_at    =>  '$',
-   reference      =>  '$',
-   content        =>  '$',
-   mime_type_id   =>  '$',
-   mime_type_text =>  '$',
-   file_name      =>  '$',
-   description    =>  '$',
-   id             =>  '$',
-   ref_key        =>  '$',
-   file_class     =>  '$',
-   src_class      =>  '$',
-   dbobject       =>  'LedgerSMB::DBObject',
-   file_path      =>  '$',
-   sizex          =>  '$',
-   sizey          =>  '$',
-   x_info         =>  '%'
-};
-
 my $logger = Log::Log4perl->get_logger('LedgerSMB::File');
 
 =head1 METHODS
 
 =over
 
-=item new
-
-Returns a blessed object
-
-=item to_hashref
-
-Returns a hashref of properties for the object.
-
-=cut
-
-sub to_hashref {
-    my $self = shift @_;
-    my $hashref = {    attached_by_id =>  $self->attached_by_id,
-                       attached_by    =>  $self->attached_by,
-                       attached_at    =>  $self->attached_at,
-                       reference      =>  $self->reference,
-                       content        =>  $self->content,
-                       mime_type_id   =>  $self->mime_type_id,
-                       mime_type_text =>  $self->mime_type_text,
-                       file_name      =>  $self->file_name,
-                       description    =>  $self->description,
-                       id             =>  $self->id,
-                       ref_key        =>  $self->ref_key,
-                       file_class     =>  $self->file_class,
-                       src_class      =>  $self->sec_class,
-                       dbobject       =>  $self->dbobject,
-                       x_info         =>  \{$self->x_info}
-    };
-    return $hashref;
-
-}
-
-=item new_dbobject
-
-$file->new_dbobject({base => (LedgerSMB | LedgerSMB::Form), 
-locale => LedgerSMB::Locale}); 
-
-Creates a new file object.  Locale only needs to be specified when using
-LedgerSMB::Form objects since these are not included.
-
-Returns 0 on success.
-
-Error codes on exit (OR'd):
-
-1:  No database handle included
-2:  No locale handle included
-4:  Invalid base.
-
-In most cases when working with new code it is simpler to just
-
-$file->dbobject(LedgerSMB::DBObject->new({base => $request});
-
-=cut
-
-sub new_dbobject{
-    use LedgerSMB;
-    my ($self, $args)  = @_;
-    my $dbobject;
-    my $rc = 0; # Success
-    $logger->debug("begin");
-    $logger->trace("self=".Data::Dumper::Dumper(\$self)." args=".Data::Dumper::Dumper(\$args)." ref=".ref($args->{base}));
-    if (ref $args->{base} eq 'Form'){
-         #$ENV{LSMB_NOHEAD} = 1;
-         use LedgerSMB::Locale;
-         #HV trying to avoid msg:Issuing rollback() due to DESTROY without explicit disconnect() of DBD::Pg::db handle
-         # new LedgerSMB will acquire dbh_handle.This newly created dbh_handle will be unset in merge() with dbh_handle from Form
-         $logger->debug("LedgerSMB->new begin");
-         my $lsmb = LedgerSMB->new($args->{base}->{dbh});
-         $logger->debug("LedgerSMB->new end");
-         $logger->debug("LedgerSMB->merge begin");
-         $lsmb->merge($args->{base});
-         $logger->debug("LedgerSMB->merge end");
-         if ((ref $args->{locale}) =~ /^LedgerSMB::Locale/){
-             $lsmb->{_locale} = $args->{locale};
-             $dbobject = LedgerSMB::DBObject->new({base => $lsmb});
-             $logger->debug("\$dbobject->{dbh}=$dbobject->{dbh}");
-         } else {
-             $rc | 2; # No locale
-         }
-    }
-    elsif (LedgerSMB->isa($args->{base})){
-         $dbobject = LedgerSMB::DBObject->new({base => $args->{base}});
-    }
-    else {
-        $rc | 4; # Incorrect base type
-    }
-    $logger->debug("end");
-    if (!$dbobject->{dbh}){
-        $rc | 1; # No database handle
-    }
-    if ($rc){
-        return $rc;  # Return error.
-    } else {
-        
-        $self->dbobject($dbobject);
-        return 0;
-    }
-}
-
 =item get_mime_type
 
 Sends the textual representation of the MIME type.  If not set, retrieves and
@@ -368,37 +295,6 @@
     return @results;
 }
 
-=item exec_method
-
-Provides a compatible interface to LedgerSMB::DBObject::exec_method
-
-=cut
-
-sub exec_method{
-    use DBD::Pg qw(:pg_types);
-    my ($self, $args) = @_;
-    if (!$args->{args}){
-          $self->dbobject->{attached_by_id} = $self->attached_by_id;
-          $self->dbobject->{attached_by}    = $self->attached_by;
-          $self->dbobject->{attached_at}    = $self->attached_at;
-          $self->dbobject->{reference}      = $self->reference;
-          $self->dbobject->{content}        = {value => $self->content,
-                                                type => DBD::Pg::PG_BYTEA};
-          $self->dbobject->{mime_type_id}   = $self->mime_type_id;
-          $self->dbobject->{mime_type_text} = $self->mime_type_text;
-          $self->dbobject->{file_name}      = $self->file_name;
-          $self->dbobject->{description}    = $self->description;
-          $self->dbobject->{id}             = $self->id;
-          $self->dbobject->{ref_key}        = $self->ref_key;
-          $self->dbobject->{file_class}     = $self->file_class;
-          $self->dbobject->{src_class}      = $self->src_class;
-          $self->dbobject->{dbobject}       = $self->dbobject;
-          $self->dbobject->{x_info}         = $self->x_info;
-    }
-    my @results = $self->dbobject->exec_method($args);
-    return @results;
-}
-
 =item merge(hashref)
 
 Merges in specific attributes from the ref.
@@ -447,4 +343,6 @@
 
 =cut
 
+__PACKAGE__->meta->make_immutable;
+
 1;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.