blib/lib/Catalyst/Model/Sedna.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary
1 package Catalyst::Model::Sedna;
2 0 ▶use Sedna;
Subroutine BEGIN: called CC=1 SCAR=2.6
3 use Moose;
4  
5 our $VERSION = 0.004;
6  
7 extends 'Catalyst::Model';
8 has 'conn' => (is => 'ro',
9 isa => 'Sedna',
10 required => 1,
11 handles => [qw(execute begin
12 rollback getData
13 next commit )]);
14  
15 __PACKAGE__->meta->make_immutable;
16  
17 sub BUILDARGS {
18 my ($self, $c, $config) = @_;
19  
20 my $conn =
21 Sedna->connect($config->{url},
22 $config->{db_name},
23 $config->{login},
24 $config->{password});
25  
26 $conn->setConnectionAttr(%{$config->{attr}})
27 if exists $config->{attr} &&
28 ref $config->{attr} eq 'HASH';
29  
30 return { conn => $conn };
31 }
32  
33 sub get_item {
34 my $self = shift;
35 if ($self->conn->next) {
36 return $self->conn->getItem;
37 } else {
38 return;
39 }
40 }
41  
42  
43 sub get_document {
44 my ( $self, $doc ) = @_;
45 $self->execute( 'for $x in doc("' . $doc . '") return $x' );
46 my $data = $self->get_item;
47 return $data;
48 }
49  
50 sub store_document {
51 my ( $self, $xml, $doc_id, $collection ) = @_;
52 $self->conn->loadData( $xml, $doc_id, $collection );
53 $self->conn->endLoadData();
54 }
55  
56 42;
57  
58 __END__
↑ Summary